array_unique
주어진 인자로 주어진 배열의 값들 중, 중복되는 값을 제외하고, 중복이 없는 것만을 모아 새로운 배열로 만든후 반환합니다.
Takes an input array and returns a new array without duplicate values.
array_unique 를 사용 하면 아래와 같이 쉽게 중복을 제거한 배열을 얻을수 있습니다.
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?> Array(
[a] => green
[0] => red
[1] => blue
)
문제> array_unique 를 사용하지 않고 위와 동일한 문제에 동일한 답이 나오도록 처리하세요.
제한시간 - 30분
댓글 16개
14년 전
우와 신선한데요?
function array_unique_custom($arr){
while (list($key, $value) = each($arr)) {
if($$value == true) unset($arr[$key]);
$$value = true;
}
return $arr;
}
function array_unique_custom($arr){
while (list($key, $value) = each($arr)) {
if($$value == true) unset($arr[$key]);
$$value = true;
}
return $arr;
}
14년 전
in_array면 간단할거 같은데 그 함수도 안되면 루프를 2번 돌려야될듯;;
14년 전
상관없습니다. 문제 그대로 입니다.
14년 전
코딩하기는 싫고,,
key -> value 구조를 value->key 구조로 convert 하신후 다시 value->key를 한번더 돌리면 됩니다.
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$temp = array();
$result = array();
foreach($input as $key=>$value) {
if(!isset($temp["{$value}"]))
$temp["{$value}"] = $key;
}
foreach($temp as $key=>$value) {
$result["{$value}"] = $key;
}
key -> value 구조를 value->key 구조로 convert 하신후 다시 value->key를 한번더 돌리면 됩니다.
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$temp = array();
$result = array();
foreach($input as $key=>$value) {
if(!isset($temp["{$value}"]))
$temp["{$value}"] = $key;
}
foreach($temp as $key=>$value) {
$result["{$value}"] = $key;
}
14년 전
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = xarray_unique($input);
print_r($result);
function xarray_unique($input) {
$rtn=array();
while (list($key,$value)=each($input)) {
if (!in_array($value,$rtn,true)) {
$rtn["{$key}"]=$value;
}
}
return $rtn;
}
$result = xarray_unique($input);
print_r($result);
function xarray_unique($input) {
$rtn=array();
while (list($key,$value)=each($input)) {
if (!in_array($value,$rtn,true)) {
$rtn["{$key}"]=$value;
}
}
return $rtn;
}
14년 전
저도 명랑폐인님 같은 생각했는데, 그냥
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
print_r(array_merge(array_flip(array_flip($input))));
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
print_r(array_merge(array_flip(array_flip($input))));
14년 전
오 이건 생각의 전환인데요...멋집니다
14년 전
저도
<?
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$output = array();
foreach($input as $k=>$v) {
if (!in_array($v, $output)) {
$output[$k] = $v;
}
}
print_r($output);
?>
Array
(
[a] => green
[0] => red
[1] => blue
)
<?
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$output = array();
foreach($input as $k=>$v) {
if (!in_array($v, $output)) {
$output[$k] = $v;
}
}
print_r($output);
?>
Array
(
[a] => green
[0] => red
[1] => blue
)
14년 전
print_r(array_flip(array_flip(array_reverse($input, true))));
14년 전
WoW !
이러니 배추빌더가 쵝오지!!!
이러니 배추빌더가 쵝오지!!!
14년 전
털석OTL
연구해보니 답은 맞습니다만. 이거 태클의 여지가 좀...
어째든 대단하십니다. 발상자체가 다르군요.
연구해보니 답은 맞습니다만. 이거 태클의 여지가 좀...
어째든 대단하십니다. 발상자체가 다르군요.
14년 전
마치 무림고수처럼... 휘리릭!!!
FineTheWay
14년 전
우와 단 한줄로 끝내시네요~ 저도 배추빌더 회원인데 ㅋㅋㅋ
14년 전
헉, 과찬들이십니다.
다른 분들 답변보고 다른 방법은 없을까? 하며
매뉴얼 뒤져본 것 뿐입니다.
저는 인터넷 안되면 코딩을 못한다는....>.<
다른 분들 답변보고 다른 방법은 없을까? 하며
매뉴얼 뒤져본 것 뿐입니다.
저는 인터넷 안되면 코딩을 못한다는....>.<
14년 전
기초는 아닌듯 ^^
14년 전
ㅎㅎ
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7930 | 9년 전 | 418 | ||
| 7929 | 9년 전 | 341 | ||
| 7928 | 9년 전 | 432 | ||
| 7927 | 9년 전 | 350 | ||
| 7926 | 9년 전 | 672 | ||
| 7925 | 9년 전 | 369 | ||
| 7924 | 9년 전 | 344 | ||
| 7923 | 9년 전 | 352 | ||
| 7922 | 9년 전 | 390 | ||
| 7921 | 9년 전 | 407 | ||
| 7920 | 9년 전 | 324 | ||
| 7919 | 9년 전 | 339 | ||
| 7918 | 9년 전 | 496 | ||
| 7917 | 9년 전 | 346 | ||
| 7916 | 9년 전 | 420 | ||
| 7915 | 9년 전 | 411 | ||
| 7914 | 9년 전 | 432 | ||
| 7913 | 9년 전 | 590 | ||
| 7912 | 9년 전 | 432 | ||
| 7911 | 9년 전 | 375 | ||
| 7910 | 9년 전 | 417 | ||
| 7909 | 9년 전 | 514 | ||
| 7908 | 9년 전 | 439 | ||
| 7907 | 9년 전 | 384 | ||
| 7906 | 9년 전 | 403 | ||
| 7905 | 9년 전 | 384 | ||
| 7904 | 9년 전 | 369 | ||
| 7903 | 9년 전 | 360 | ||
| 7902 | 9년 전 | 567 | ||
| 7901 |
|
9년 전 | 746 | |
| 7900 | 9년 전 | 602 | ||
| 7899 | 9년 전 | 400 | ||
| 7898 | 9년 전 | 399 | ||
| 7897 | 9년 전 | 357 | ||
| 7896 | 9년 전 | 367 | ||
| 7895 | 9년 전 | 480 | ||
| 7894 | 9년 전 | 402 | ||
| 7893 | 9년 전 | 361 | ||
| 7892 | 9년 전 | 406 | ||
| 7891 | 9년 전 | 776 | ||
| 7890 | 9년 전 | 1203 | ||
| 7889 | 9년 전 | 752 | ||
| 7888 |
limsy1987
|
9년 전 | 557 | |
| 7887 | 9년 전 | 569 | ||
| 7886 | 9년 전 | 460 | ||
| 7885 | 9년 전 | 423 | ||
| 7884 | 9년 전 | 423 | ||
| 7883 | 9년 전 | 420 | ||
| 7882 | 9년 전 | 470 | ||
| 7881 | 9년 전 | 452 | ||
| 7880 | 9년 전 | 587 | ||
| 7879 | 9년 전 | 475 | ||
| 7878 | 9년 전 | 1229 | ||
| 7877 | 9년 전 | 765 | ||
| 7876 | 9년 전 | 500 | ||
| 7875 | 9년 전 | 571 | ||
| 7874 |
|
9년 전 | 814 | |
| 7873 | 9년 전 | 528 | ||
| 7872 | 9년 전 | 689 | ||
| 7871 | 9년 전 | 491 | ||
| 7870 | 9년 전 | 618 | ||
| 7869 | 9년 전 | 439 | ||
| 7868 | 9년 전 | 463 | ||
| 7867 | 9년 전 | 437 | ||
| 7866 | 9년 전 | 505 | ||
| 7865 | 9년 전 | 462 | ||
| 7864 | 9년 전 | 522 | ||
| 7863 | 9년 전 | 521 | ||
| 7862 | 9년 전 | 474 | ||
| 7861 | 9년 전 | 654 | ||
| 7860 | 9년 전 | 635 | ||
| 7859 | 9년 전 | 423 | ||
| 7858 | 9년 전 | 709 | ||
| 7857 | 9년 전 | 1089 | ||
| 7856 | 9년 전 | 536 | ||
| 7855 | 9년 전 | 763 | ||
| 7854 | 9년 전 | 735 | ||
| 7853 | 9년 전 | 594 | ||
| 7852 | 9년 전 | 519 | ||
| 7851 | 9년 전 | 520 | ||
| 7850 | 9년 전 | 595 | ||
| 7849 | 9년 전 | 364 | ||
| 7848 | 9년 전 | 426 | ||
| 7847 | 9년 전 | 667 | ||
| 7846 | 9년 전 | 466 | ||
| 7845 | 9년 전 | 433 | ||
| 7844 | 9년 전 | 403 | ||
| 7843 | 9년 전 | 425 | ||
| 7842 | 9년 전 | 413 | ||
| 7841 | 9년 전 | 393 | ||
| 7840 | 9년 전 | 414 | ||
| 7839 | 9년 전 | 442 | ||
| 7838 | 9년 전 | 523 | ||
| 7837 | 9년 전 | 364 | ||
| 7836 | 9년 전 | 407 | ||
| 7835 | 9년 전 | 483 | ||
| 7834 |
|
9년 전 | 1201 | |
| 7833 | 9년 전 | 447 | ||
| 7832 | 9년 전 | 429 | ||
| 7831 | 9년 전 | 576 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기