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년 전
ㅎㅎ
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 4230 |
|
14년 전 | 1558 | |
| 4229 | 14년 전 | 1117 | ||
| 4228 | 14년 전 | 2113 | ||
| 4227 | 14년 전 | 800 | ||
| 4226 |
|
14년 전 | 820 | |
| 4225 |
천국의눈믈
|
14년 전 | 638 | |
| 4224 |
visualp
|
14년 전 | 1437 | |
| 4223 |
visualp
|
14년 전 | 1050 | |
| 4222 |
visualp
|
14년 전 | 773 | |
| 4221 |
visualp
|
14년 전 | 5304 | |
| 4220 | 14년 전 | 1907 | ||
| 4219 | 14년 전 | 1151 | ||
| 4218 | 14년 전 | 645 | ||
| 4217 | 14년 전 | 9443 | ||
| 4216 | 14년 전 | 1558 | ||
| 4215 |
|
14년 전 | 575 | |
| 4214 | 14년 전 | 564 | ||
| 4213 | 14년 전 | 1434 | ||
| 4212 |
visualp
|
14년 전 | 2014 | |
| 4211 | 14년 전 | 1558 | ||
| 4210 | 14년 전 | 827 | ||
| 4209 |
|
14년 전 | 2053 | |
| 4208 | 14년 전 | 2054 | ||
| 4207 | 14년 전 | 3006 | ||
| 4206 | 14년 전 | 1101 | ||
| 4205 |
SGFlash
|
14년 전 | 1287 | |
| 4204 | 14년 전 | 816 | ||
| 4203 | 14년 전 | 896 | ||
| 4202 | 14년 전 | 2116 | ||
| 4201 | 14년 전 | 910 | ||
| 4200 | 14년 전 | 2381 | ||
| 4199 | 14년 전 | 632 | ||
| 4198 |
visualp
|
14년 전 | 3509 | |
| 4197 |
visualp
|
14년 전 | 733 | |
| 4196 | 14년 전 | 2091 | ||
| 4195 |
미사카10777호
|
14년 전 | 3470 | |
| 4194 |
senseme
|
14년 전 | 777 | |
| 4193 | 14년 전 | 955 | ||
| 4192 | 14년 전 | 1309 | ||
| 4191 |
DreamT
|
14년 전 | 802 | |
| 4190 |
onlymilk74
|
14년 전 | 1316 | |
| 4189 | 14년 전 | 1251 | ||
| 4188 | 14년 전 | 1374 | ||
| 4187 | 14년 전 | 1108 | ||
| 4186 |
|
14년 전 | 734 | |
| 4185 | 14년 전 | 1196 | ||
| 4184 | 14년 전 | 1176 | ||
| 4183 |
visualp
|
14년 전 | 1050 | |
| 4182 |
visualp
|
14년 전 | 627 | |
| 4181 |
|
14년 전 | 622 | |
| 4180 |
techer
|
14년 전 | 955 | |
| 4179 | 14년 전 | 526 | ||
| 4178 | 14년 전 | 3080 | ||
| 4177 | 14년 전 | 601 | ||
| 4176 | 14년 전 | 947 | ||
| 4175 | 14년 전 | 599 | ||
| 4174 |
|
14년 전 | 632 | |
| 4173 |
|
14년 전 | 1860 | |
| 4172 |
|
14년 전 | 907 | |
| 4171 | 14년 전 | 1396 | ||
| 4170 | 14년 전 | 665 | ||
| 4169 | 14년 전 | 1294 | ||
| 4168 | 14년 전 | 1775 | ||
| 4167 | 14년 전 | 818 | ||
| 4166 | 14년 전 | 1324 | ||
| 4165 |
visualp
|
14년 전 | 814 | |
| 4164 | 14년 전 | 1179 | ||
| 4163 | 14년 전 | 2606 | ||
| 4162 | 14년 전 | 660 | ||
| 4161 |
onlymilk74
|
14년 전 | 4798 | |
| 4160 | 14년 전 | 685 | ||
| 4159 | 14년 전 | 872 | ||
| 4158 | 14년 전 | 711 | ||
| 4157 | 14년 전 | 3391 | ||
| 4156 | 14년 전 | 505 | ||
| 4155 | 14년 전 | 840 | ||
| 4154 | 14년 전 | 1141 | ||
| 4153 | 14년 전 | 1144 | ||
| 4152 | 14년 전 | 636 | ||
| 4151 | 14년 전 | 1247 | ||
| 4150 | 14년 전 | 724 | ||
| 4149 | 14년 전 | 628 | ||
| 4148 |
쉽다zzz
|
14년 전 | 2265 | |
| 4147 | 14년 전 | 955 | ||
| 4146 | 14년 전 | 580 | ||
| 4145 | 14년 전 | 579 | ||
| 4144 | 14년 전 | 1619 | ||
| 4143 | 14년 전 | 772 | ||
| 4142 | 14년 전 | 1178 | ||
| 4141 | 14년 전 | 1166 | ||
| 4140 |
|
14년 전 | 1774 | |
| 4139 |
visualp
|
14년 전 | 1849 | |
| 4138 |
visualp
|
14년 전 | 1115 | |
| 4137 | 14년 전 | 770 | ||
| 4136 | 14년 전 | 712 | ||
| 4135 | 14년 전 | 961 | ||
| 4134 | 14년 전 | 1118 | ||
| 4133 | 14년 전 | 2532 | ||
| 4132 | 14년 전 | 580 | ||
| 4131 | 14년 전 | 896 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기