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년 전 | 936 | ||
| 3829 | 14년 전 | 1681 | ||
| 3828 | 14년 전 | 958 | ||
| 3827 |
방황하는중년
|
14년 전 | 911 | |
| 3826 |
|
14년 전 | 1640 | |
| 3825 | 14년 전 | 879 | ||
| 3824 | 14년 전 | 730 | ||
| 3823 | 14년 전 | 741 | ||
| 3822 |
level999
|
14년 전 | 834 | |
| 3821 | 14년 전 | 1019 | ||
| 3820 |
TzM위드컴
|
14년 전 | 939 | |
| 3819 | 14년 전 | 993 | ||
| 3818 |
base64
|
14년 전 | 1104 | |
| 3817 |
base64
|
14년 전 | 970 | |
| 3816 | 14년 전 | 2241 | ||
| 3815 | 14년 전 | 1871 | ||
| 3814 |
|
14년 전 | 2535 | |
| 3813 | 14년 전 | 509 | ||
| 3812 | 14년 전 | 810 | ||
| 3811 | 14년 전 | 1074 | ||
| 3810 | 14년 전 | 679 | ||
| 3809 |
스님꼬신수녀
|
14년 전 | 659 | |
| 3808 | 14년 전 | 1461 | ||
| 3807 | 14년 전 | 1275 | ||
| 3806 | 14년 전 | 2371 | ||
| 3805 | 14년 전 | 1267 | ||
| 3804 | 14년 전 | 857 | ||
| 3803 | 14년 전 | 3375 | ||
| 3802 | 14년 전 | 1595 | ||
| 3801 | 14년 전 | 1007 | ||
| 3800 | 14년 전 | 1361 | ||
| 3799 | 14년 전 | 720 | ||
| 3798 |
커피는막심
|
14년 전 | 1842 | |
| 3797 | 14년 전 | 777 | ||
| 3796 | 14년 전 | 1207 | ||
| 3795 | 14년 전 | 713 | ||
| 3794 |
방황하는중년
|
14년 전 | 1248 | |
| 3793 | 14년 전 | 1486 | ||
| 3792 | 14년 전 | 1001 | ||
| 3791 | 14년 전 | 793 | ||
| 3790 | 14년 전 | 1010 | ||
| 3789 | 14년 전 | 937 | ||
| 3788 | 14년 전 | 1956 | ||
| 3787 | 14년 전 | 1120 | ||
| 3786 | 14년 전 | 816 | ||
| 3785 | 14년 전 | 712 | ||
| 3784 | 14년 전 | 1328 | ||
| 3783 | 14년 전 | 2620 | ||
| 3782 | 14년 전 | 710 | ||
| 3781 |
|
14년 전 | 2548 | |
| 3780 |
헬프데스크
|
14년 전 | 1665 | |
| 3779 |
방황하는중년
|
14년 전 | 901 | |
| 3778 |
|
14년 전 | 1109 | |
| 3777 |
|
14년 전 | 1016 | |
| 3776 |
스누피사랑
|
14년 전 | 998 | |
| 3775 |
silver31
|
14년 전 | 506 | |
| 3774 |
|
14년 전 | 718 | |
| 3773 | 14년 전 | 816 | ||
| 3772 |
|
14년 전 | 1178 | |
| 3771 | 14년 전 | 875 | ||
| 3770 | 14년 전 | 1229 | ||
| 3769 | 14년 전 | 1013 | ||
| 3768 |
Dokjin
|
14년 전 | 1114 | |
| 3767 |
Dokjin
|
14년 전 | 714 | |
| 3766 | 14년 전 | 1025 | ||
| 3765 |
|
14년 전 | 923 | |
| 3764 | 14년 전 | 806 | ||
| 3763 | 14년 전 | 694 | ||
| 3762 | 14년 전 | 1176 | ||
| 3761 |
쉽다zzz
|
14년 전 | 1583 | |
| 3760 |
gtm100
|
14년 전 | 941 | |
| 3759 |
원시인교주
|
14년 전 | 784 | |
| 3758 | 14년 전 | 3320 | ||
| 3757 | 14년 전 | 849 | ||
| 3756 | 14년 전 | 736 | ||
| 3755 | 14년 전 | 2134 | ||
| 3754 | 14년 전 | 1519 | ||
| 3753 | 14년 전 | 2033 | ||
| 3752 | 14년 전 | 600 | ||
| 3751 | 14년 전 | 857 | ||
| 3750 |
방황하는중년
|
14년 전 | 717 | |
| 3749 |
hopeone
|
14년 전 | 550 | |
| 3748 | 14년 전 | 637 | ||
| 3747 | 14년 전 | 764 | ||
| 3746 | 14년 전 | 1515 | ||
| 3745 | 14년 전 | 873 | ||
| 3744 | 14년 전 | 915 | ||
| 3743 | 14년 전 | 549 | ||
| 3742 | 14년 전 | 1083 | ||
| 3741 | 14년 전 | 1669 | ||
| 3740 |
매너천사12
|
14년 전 | 1066 | |
| 3739 |
SGFlash
|
14년 전 | 1397 | |
| 3738 |
C2HGroup
|
14년 전 | 918 | |
| 3737 | 14년 전 | 1051 | ||
| 3736 | 14년 전 | 811 | ||
| 3735 | 14년 전 | 1122 | ||
| 3734 | 14년 전 | 1009 | ||
| 3733 | 14년 전 | 422 | ||
| 3732 | 14년 전 | 565 | ||
| 3731 | 14년 전 | 643 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기