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년 전
ㅎㅎ
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3830 | 14년 전 | 918 | ||
| 3829 | 14년 전 | 1666 | ||
| 3828 | 14년 전 | 950 | ||
| 3827 |
방황하는중년
|
14년 전 | 900 | |
| 3826 |
|
14년 전 | 1637 | |
| 3825 | 14년 전 | 870 | ||
| 3824 | 14년 전 | 722 | ||
| 3823 | 14년 전 | 731 | ||
| 3822 |
level999
|
14년 전 | 824 | |
| 3821 | 14년 전 | 1013 | ||
| 3820 |
TzM위드컴
|
14년 전 | 930 | |
| 3819 | 14년 전 | 982 | ||
| 3818 |
base64
|
14년 전 | 1094 | |
| 3817 |
base64
|
14년 전 | 961 | |
| 3816 | 14년 전 | 2232 | ||
| 3815 | 14년 전 | 1857 | ||
| 3814 |
|
14년 전 | 2531 | |
| 3813 | 14년 전 | 499 | ||
| 3812 | 14년 전 | 804 | ||
| 3811 | 14년 전 | 1063 | ||
| 3810 | 14년 전 | 664 | ||
| 3809 |
스님꼬신수녀
|
14년 전 | 643 | |
| 3808 | 14년 전 | 1443 | ||
| 3807 | 14년 전 | 1247 | ||
| 3806 | 14년 전 | 2353 | ||
| 3805 | 14년 전 | 1250 | ||
| 3804 | 14년 전 | 840 | ||
| 3803 | 14년 전 | 3362 | ||
| 3802 | 14년 전 | 1583 | ||
| 3801 | 14년 전 | 997 | ||
| 3800 | 14년 전 | 1354 | ||
| 3799 | 14년 전 | 712 | ||
| 3798 |
커피는막심
|
14년 전 | 1836 | |
| 3797 | 14년 전 | 769 | ||
| 3796 | 14년 전 | 1204 | ||
| 3795 | 14년 전 | 711 | ||
| 3794 |
방황하는중년
|
14년 전 | 1241 | |
| 3793 | 14년 전 | 1476 | ||
| 3792 | 14년 전 | 986 | ||
| 3791 | 14년 전 | 773 | ||
| 3790 | 14년 전 | 992 | ||
| 3789 | 14년 전 | 924 | ||
| 3788 | 14년 전 | 1943 | ||
| 3787 | 14년 전 | 1112 | ||
| 3786 | 14년 전 | 811 | ||
| 3785 | 14년 전 | 710 | ||
| 3784 | 14년 전 | 1321 | ||
| 3783 | 14년 전 | 2611 | ||
| 3782 | 14년 전 | 702 | ||
| 3781 |
|
14년 전 | 2535 | |
| 3780 |
헬프데스크
|
14년 전 | 1652 | |
| 3779 |
방황하는중년
|
14년 전 | 882 | |
| 3778 |
|
14년 전 | 1095 | |
| 3777 |
|
14년 전 | 994 | |
| 3776 |
스누피사랑
|
14년 전 | 983 | |
| 3775 |
silver31
|
14년 전 | 500 | |
| 3774 |
|
14년 전 | 708 | |
| 3773 | 14년 전 | 811 | ||
| 3772 |
|
14년 전 | 1174 | |
| 3771 | 14년 전 | 869 | ||
| 3770 | 14년 전 | 1227 | ||
| 3769 | 14년 전 | 1010 | ||
| 3768 |
Dokjin
|
14년 전 | 1111 | |
| 3767 |
Dokjin
|
14년 전 | 713 | |
| 3766 | 14년 전 | 1021 | ||
| 3765 |
|
14년 전 | 916 | |
| 3764 | 14년 전 | 797 | ||
| 3763 | 14년 전 | 688 | ||
| 3762 | 14년 전 | 1171 | ||
| 3761 |
쉽다zzz
|
14년 전 | 1581 | |
| 3760 |
gtm100
|
14년 전 | 935 | |
| 3759 |
원시인교주
|
14년 전 | 775 | |
| 3758 | 14년 전 | 3311 | ||
| 3757 | 14년 전 | 836 | ||
| 3756 | 14년 전 | 718 | ||
| 3755 | 14년 전 | 2109 | ||
| 3754 | 14년 전 | 1502 | ||
| 3753 | 14년 전 | 2023 | ||
| 3752 | 14년 전 | 590 | ||
| 3751 | 14년 전 | 841 | ||
| 3750 |
방황하는중년
|
14년 전 | 700 | |
| 3749 |
hopeone
|
14년 전 | 538 | |
| 3748 | 14년 전 | 621 | ||
| 3747 | 14년 전 | 749 | ||
| 3746 | 14년 전 | 1494 | ||
| 3745 | 14년 전 | 855 | ||
| 3744 | 14년 전 | 904 | ||
| 3743 | 14년 전 | 526 | ||
| 3742 | 14년 전 | 1057 | ||
| 3741 | 14년 전 | 1647 | ||
| 3740 |
매너천사12
|
14년 전 | 1042 | |
| 3739 |
SGFlash
|
14년 전 | 1327 | |
| 3738 |
C2HGroup
|
14년 전 | 844 | |
| 3737 | 14년 전 | 973 | ||
| 3736 | 14년 전 | 766 | ||
| 3735 | 14년 전 | 1095 | ||
| 3734 | 14년 전 | 996 | ||
| 3733 | 14년 전 | 414 | ||
| 3732 | 14년 전 | 547 | ||
| 3731 | 14년 전 | 628 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기