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년 전
ㅎㅎ
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 3630 | 14년 전 | 1174 | ||
| 3629 | 14년 전 | 791 | ||
| 3628 | 14년 전 | 1080 | ||
| 3627 | 14년 전 | 3025 | ||
| 3626 | 14년 전 | 1406 | ||
| 3625 | 14년 전 | 790 | ||
| 3624 | 14년 전 | 1581 | ||
| 3623 | 14년 전 | 950 | ||
| 3622 | 14년 전 | 480 | ||
| 3621 | 14년 전 | 2368 | ||
| 3620 | 14년 전 | 770 | ||
| 3619 |
하모니칼수
|
14년 전 | 833 | |
| 3618 | 14년 전 | 1142 | ||
| 3617 | 14년 전 | 1018 | ||
| 3616 |
방황하는중년
|
14년 전 | 1069 | |
| 3615 |
아놔6636
|
14년 전 | 579 | |
| 3614 |
아놔6636
|
14년 전 | 2456 | |
| 3613 | 14년 전 | 876 | ||
| 3612 |
forever
|
14년 전 | 1483 | |
| 3611 |
SaNoRaMyun
|
14년 전 | 1169 | |
| 3610 | 14년 전 | 1188 | ||
| 3609 | 14년 전 | 870 | ||
| 3608 | 14년 전 | 1169 | ||
| 3607 | 14년 전 | 743 | ||
| 3606 | 14년 전 | 760 | ||
| 3605 | 14년 전 | 1584 | ||
| 3604 | 14년 전 | 1336 | ||
| 3603 | 14년 전 | 1142 | ||
| 3602 | 14년 전 | 1193 | ||
| 3601 | 14년 전 | 1918 | ||
| 3600 | 14년 전 | 1494 | ||
| 3599 | 14년 전 | 605 | ||
| 3598 | 14년 전 | 1487 | ||
| 3597 | 14년 전 | 1268 | ||
| 3596 |
anfernee
|
14년 전 | 1355 | |
| 3595 | 14년 전 | 831 | ||
| 3594 | 14년 전 | 870 | ||
| 3593 | 14년 전 | 819 | ||
| 3592 | 14년 전 | 810 | ||
| 3591 | 14년 전 | 1452 | ||
| 3590 | 14년 전 | 780 | ||
| 3589 |
쉽다zzz
|
14년 전 | 1066 | |
| 3588 | 14년 전 | 1350 | ||
| 3587 | 14년 전 | 1399 | ||
| 3586 | 14년 전 | 1087 | ||
| 3585 |
플레이디원
|
14년 전 | 1844 | |
| 3584 |
행복한숭아씨
|
14년 전 | 1171 | |
| 3583 | 14년 전 | 1821 | ||
| 3582 |
|
14년 전 | 1371 | |
| 3581 |
|
14년 전 | 1013 | |
| 3580 |
|
14년 전 | 3097 | |
| 3579 | 14년 전 | 1542 | ||
| 3578 |
|
14년 전 | 1020 | |
| 3577 | 14년 전 | 865 | ||
| 3576 | 14년 전 | 1542 | ||
| 3575 |
|
14년 전 | 959 | |
| 3574 |
visualp
|
14년 전 | 763 | |
| 3573 |
visualp
|
14년 전 | 686 | |
| 3572 |
visualp
|
14년 전 | 1938 | |
| 3571 |
visualp
|
14년 전 | 594 | |
| 3570 | 14년 전 | 843 | ||
| 3569 | 14년 전 | 1599 | ||
| 3568 | 14년 전 | 946 | ||
| 3567 |
순천홈페이지
|
14년 전 | 931 | |
| 3566 | 14년 전 | 1473 | ||
| 3565 |
|
14년 전 | 1153 | |
| 3564 | 14년 전 | 1220 | ||
| 3563 | 14년 전 | 1015 | ||
| 3562 | 14년 전 | 2320 | ||
| 3561 | 14년 전 | 1102 | ||
| 3560 |
|
14년 전 | 829 | |
| 3559 | 14년 전 | 1012 | ||
| 3558 | 14년 전 | 765 | ||
| 3557 |
acting1
|
14년 전 | 795 | |
| 3556 |
acting1
|
14년 전 | 620 | |
| 3555 |
브라이튼스쿨
|
14년 전 | 827 | |
| 3554 | 14년 전 | 1209 | ||
| 3553 | 14년 전 | 1460 | ||
| 3552 | 14년 전 | 912 | ||
| 3551 | 14년 전 | 1065 | ||
| 3550 | 14년 전 | 916 | ||
| 3549 |
|
14년 전 | 1093 | |
| 3548 | 14년 전 | 1374 | ||
| 3547 |
|
14년 전 | 1142 | |
| 3546 |
noseart
|
14년 전 | 1335 | |
| 3545 | 14년 전 | 1109 | ||
| 3544 |
비니1234
|
14년 전 | 1039 | |
| 3543 |
비니1234
|
14년 전 | 1072 | |
| 3542 |
zerocooling
|
14년 전 | 1013 | |
| 3541 | 14년 전 | 1545 | ||
| 3540 | 14년 전 | 1494 | ||
| 3539 |
피디인사이드
|
14년 전 | 1318 | |
| 3538 |
soing
|
14년 전 | 1420 | |
| 3537 | 14년 전 | 1651 | ||
| 3536 |
|
14년 전 | 652 | |
| 3535 | 14년 전 | 1114 | ||
| 3534 | 14년 전 | 471 | ||
| 3533 | 14년 전 | 939 | ||
| 3532 | 14년 전 | 1403 | ||
| 3531 | 14년 전 | 857 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기