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년 전
ㅎㅎ
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 7830 | 9년 전 | 412 | ||
| 7829 |
|
9년 전 | 595 | |
| 7828 | 9년 전 | 529 | ||
| 7827 | 9년 전 | 420 | ||
| 7826 | 9년 전 | 428 | ||
| 7825 | 10년 전 | 466 | ||
| 7824 | 10년 전 | 440 | ||
| 7823 | 10년 전 | 366 | ||
| 7822 | 10년 전 | 348 | ||
| 7821 | 10년 전 | 303 | ||
| 7820 | 10년 전 | 344 | ||
| 7819 |
|
10년 전 | 745 | |
| 7818 | 10년 전 | 379 | ||
| 7817 | 10년 전 | 508 | ||
| 7816 | 10년 전 | 399 | ||
| 7815 | 10년 전 | 601 | ||
| 7814 | 10년 전 | 421 | ||
| 7813 | 10년 전 | 366 | ||
| 7812 | 10년 전 | 387 | ||
| 7811 | 10년 전 | 386 | ||
| 7810 | 10년 전 | 555 | ||
| 7809 | 10년 전 | 481 | ||
| 7808 | 10년 전 | 372 | ||
| 7807 | 10년 전 | 398 | ||
| 7806 |
프로그래머7
|
10년 전 | 1328 | |
| 7805 | 10년 전 | 1269 | ||
| 7804 |
zahir1312
|
10년 전 | 771 | |
| 7803 |
|
10년 전 | 1366 | |
| 7802 | 10년 전 | 453 | ||
| 7801 | 10년 전 | 856 | ||
| 7800 | 10년 전 | 1080 | ||
| 7799 | 10년 전 | 547 | ||
| 7798 | 10년 전 | 498 | ||
| 7797 | 10년 전 | 495 | ||
| 7796 | 10년 전 | 341 | ||
| 7795 | 10년 전 | 494 | ||
| 7794 | 10년 전 | 538 | ||
| 7793 | 10년 전 | 1046 | ||
| 7792 | 10년 전 | 461 | ||
| 7791 | 10년 전 | 542 | ||
| 7790 | 10년 전 | 497 | ||
| 7789 |
fbastore
|
10년 전 | 1444 | |
| 7788 | 10년 전 | 534 | ||
| 7787 | 10년 전 | 394 | ||
| 7786 | 10년 전 | 567 | ||
| 7785 | 10년 전 | 573 | ||
| 7784 | 10년 전 | 636 | ||
| 7783 | 10년 전 | 435 | ||
| 7782 | 10년 전 | 485 | ||
| 7781 | 10년 전 | 893 | ||
| 7780 | 10년 전 | 806 | ||
| 7779 | 10년 전 | 769 | ||
| 7778 | 10년 전 | 361 | ||
| 7777 | 10년 전 | 442 | ||
| 7776 | 10년 전 | 451 | ||
| 7775 | 10년 전 | 397 | ||
| 7774 | 10년 전 | 630 | ||
| 7773 | 10년 전 | 374 | ||
| 7772 | 10년 전 | 725 | ||
| 7771 | 10년 전 | 372 | ||
| 7770 | 10년 전 | 640 | ||
| 7769 | 10년 전 | 368 | ||
| 7768 | 10년 전 | 597 | ||
| 7767 | 10년 전 | 1163 | ||
| 7766 | 10년 전 | 487 | ||
| 7765 | 10년 전 | 511 | ||
| 7764 |
잘살아보자
|
10년 전 | 372 | |
| 7763 |
|
10년 전 | 1442 | |
| 7762 |
Tosea
|
10년 전 | 1047 | |
| 7761 | 10년 전 | 640 | ||
| 7760 |
잘살아보자
|
10년 전 | 670 | |
| 7759 |
잘살아보자
|
10년 전 | 497 | |
| 7758 |
잘살아보자
|
10년 전 | 583 | |
| 7757 | 10년 전 | 1236 | ||
| 7756 |
ITBANK
|
10년 전 | 1247 | |
| 7755 | 10년 전 | 1924 | ||
| 7754 | 10년 전 | 1046 | ||
| 7753 | 10년 전 | 880 | ||
| 7752 | 10년 전 | 1382 | ||
| 7751 |
잘살아보자
|
10년 전 | 518 | |
| 7750 |
잘살아보자
|
10년 전 | 472 | |
| 7749 |
잘살아보자
|
10년 전 | 478 | |
| 7748 |
잘살아보자
|
10년 전 | 473 | |
| 7747 |
잘살아보자
|
10년 전 | 567 | |
| 7746 |
잘살아보자
|
10년 전 | 672 | |
| 7745 |
잘살아보자
|
10년 전 | 905 | |
| 7744 |
잘살아보자
|
10년 전 | 408 | |
| 7743 | 10년 전 | 942 | ||
| 7742 |
starbros
|
10년 전 | 830 | |
| 7741 |
잘살아보자
|
10년 전 | 665 | |
| 7740 |
잘살아보자
|
10년 전 | 519 | |
| 7739 |
잘살아보자
|
10년 전 | 459 | |
| 7738 |
잘살아보자
|
10년 전 | 522 | |
| 7737 |
잘살아보자
|
10년 전 | 488 | |
| 7736 |
잘살아보자
|
10년 전 | 512 | |
| 7735 |
잘살아보자
|
10년 전 | 839 | |
| 7734 |
잘살아보자
|
10년 전 | 424 | |
| 7733 |
잘살아보자
|
10년 전 | 538 | |
| 7732 |
잘살아보자
|
10년 전 | 691 | |
| 7731 |
잘살아보자
|
10년 전 | 613 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기