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년 전
ㅎㅎ
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 8230 | 9년 전 | 81 | ||
| 8229 | 9년 전 | 77 | ||
| 8228 |
커네드커네드
|
9년 전 | 116 | |
| 8227 | 9년 전 | 132 | ||
| 8226 | 9년 전 | 168 | ||
| 8225 | 9년 전 | 155 | ||
| 8224 | 9년 전 | 150 | ||
| 8223 | 9년 전 | 118 | ||
| 8222 |
|
9년 전 | 193 | |
| 8221 | 9년 전 | 95 | ||
| 8220 | 9년 전 | 107 | ||
| 8219 | 9년 전 | 104 | ||
| 8218 | 9년 전 | 149 | ||
| 8217 |
star3840
|
9년 전 | 117 | |
| 8216 | 9년 전 | 166 | ||
| 8215 | 9년 전 | 123 | ||
| 8214 | 9년 전 | 231 | ||
| 8213 | 9년 전 | 165 | ||
| 8212 | 9년 전 | 86 | ||
| 8211 | 9년 전 | 250 | ||
| 8210 | 9년 전 | 254 | ||
| 8209 | 9년 전 | 343 | ||
| 8208 | 9년 전 | 227 | ||
| 8207 | 9년 전 | 232 | ||
| 8206 |
|
9년 전 | 196 | |
| 8205 | 9년 전 | 176 | ||
| 8204 | 9년 전 | 139 | ||
| 8203 | 9년 전 | 237 | ||
| 8202 | 9년 전 | 150 | ||
| 8201 | 9년 전 | 186 | ||
| 8200 | 9년 전 | 171 | ||
| 8199 | 9년 전 | 221 | ||
| 8198 | 9년 전 | 181 | ||
| 8197 | 9년 전 | 168 | ||
| 8196 | 9년 전 | 558 | ||
| 8195 | 9년 전 | 166 | ||
| 8194 | 9년 전 | 288 | ||
| 8193 | 9년 전 | 161 | ||
| 8192 | 9년 전 | 202 | ||
| 8191 | 9년 전 | 147 | ||
| 8190 | 9년 전 | 136 | ||
| 8189 | 9년 전 | 196 | ||
| 8188 | 9년 전 | 131 | ||
| 8187 | 9년 전 | 150 | ||
| 8186 | 9년 전 | 150 | ||
| 8185 | 9년 전 | 318 | ||
| 8184 | 9년 전 | 112 | ||
| 8183 | 9년 전 | 331 | ||
| 8182 | 9년 전 | 172 | ||
| 8181 | 9년 전 | 137 | ||
| 8180 | 9년 전 | 700 | ||
| 8179 | 9년 전 | 491 | ||
| 8178 | 9년 전 | 316 | ||
| 8177 |
kiplayer
|
9년 전 | 332 | |
| 8176 | 9년 전 | 356 | ||
| 8175 | 9년 전 | 229 | ||
| 8174 | 9년 전 | 252 | ||
| 8173 | 9년 전 | 348 | ||
| 8172 | 9년 전 | 205 | ||
| 8171 | 9년 전 | 187 | ||
| 8170 | 9년 전 | 299 | ||
| 8169 |
커네드커네드
|
9년 전 | 263 | |
| 8168 | 9년 전 | 325 | ||
| 8167 | 9년 전 | 325 | ||
| 8166 | 9년 전 | 244 | ||
| 8165 | 9년 전 | 175 | ||
| 8164 | 9년 전 | 308 | ||
| 8163 | 9년 전 | 293 | ||
| 8162 | 9년 전 | 308 | ||
| 8161 | 9년 전 | 301 | ||
| 8160 |
|
9년 전 | 498 | |
| 8159 | 9년 전 | 434 | ||
| 8158 | 9년 전 | 258 | ||
| 8157 | 9년 전 | 384 | ||
| 8156 | 9년 전 | 279 | ||
| 8155 | 9년 전 | 259 | ||
| 8154 |
00년생용띠
|
9년 전 | 605 | |
| 8153 | 9년 전 | 236 | ||
| 8152 |
|
9년 전 | 416 | |
| 8151 | 9년 전 | 410 | ||
| 8150 | 9년 전 | 507 | ||
| 8149 |
Jangfolk
|
9년 전 | 353 | |
| 8148 | 9년 전 | 177 | ||
| 8147 | 9년 전 | 379 | ||
| 8146 | 9년 전 | 445 | ||
| 8145 | 9년 전 | 387 | ||
| 8144 | 9년 전 | 355 | ||
| 8143 | 9년 전 | 200 | ||
| 8142 | 9년 전 | 428 | ||
| 8141 | 9년 전 | 385 | ||
| 8140 | 9년 전 | 933 | ||
| 8139 | 9년 전 | 266 | ||
| 8138 |
전갈자리남자
|
9년 전 | 391 | |
| 8137 | 9년 전 | 401 | ||
| 8136 | 9년 전 | 754 | ||
| 8135 |
|
9년 전 | 802 | |
| 8134 |
PlayPixel
|
9년 전 | 520 | |
| 8133 |
|
9년 전 | 443 | |
| 8132 | 9년 전 | 456 | ||
| 8131 | 9년 전 | 818 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기