2013-05-19 4 views
0

예를 들어 var $ test가 있고 출력이 아래에 있습니다. 복제본을 볼 수 있습니다. 중복되지 않도록하려면 어떻게해야합니까? 거기에 어떤 기능이 있습니까?어레이를 복제하는 방법

Array ( 
     [title] => Array ( 
      [0] => this field is required 
      [1] => must be longer than2 
     ) 
     [subtitle] => Array ( 
      [0] => this field is required 
      [1] => must be longer than2 
     ) 
)  
Array ( 
     [title] => Array ( 
      [0] => this field is required 
      [1] => must be longer than2 
     ) 
     [subtitle] => Array ( 
      [0] => this field is required 
      [1] => must be longer than2 
     ) 
)  

예상 결과 :

Array ( 
     [title] => Array ( 
      [0] => this field is required 
      [1] => must be longer than2 
     ) 
     [subtitle] => Array ( 
      [0] => this field is required 
      [1] => must be longer than2 
     ) 
)  
+0

는 적어도 [array_unique (http://php.net/manual/en/function.array-unique.php)를 시도 했습니까? – adeneo

+0

그것은 길다. 그러나 이것을 시도해 보셨습니까? http://dk1.php.net/manual/en/function.array-unique.php – Nikola

+0

예, array_unique ($ test); 나 일하지 않는다 – Bas

답변

2
function intersect($data=NULL){ 
     if(!empty($data)){$crashed = array(); 
     $crashed2 = array(); 
     foreach($data[0] as $key=>$val){ 
      if(!is_array($val)){ 
       $crashed[$key] = in_array($val,$data[1]);//return true if crashed(intersect) 
       }else{ 
       $crashed2[$key] = intersect(array($val,$data[1])); 
       } 
     $crashed = array_merge($crashed,$crashed2); 
     } 
    }return $crashed; 
    } 
    $intersect =intersect(array($array1,$array2)); 
    print_r($intersect); 
1

당신은 사용할 수 있습니다;

$unique = array_map("unserialize", array_unique(array_map("serialize", $array))); 
print_r($unique); 

See Live Demo

+0

@ 바바 죄송합니다, 잘못된 배열, 내가 그것을 업데이 트했습니다. 만약 내가 print_r 그러면 내가이 배열을 얻을. 이전 didnt 일. – Bas

+0

귀하의 질문에 귀하의 결과를 추가하십시오. – Baba

+0

Done Baba, just a singleele, 당신이 도울 수 있기를 바랍니다! – Bas