2012-04-25 88 views
1

我想在php中刪除數組中的重複元素。以下是陣列的結構在php中刪除數組中的重複項

Array 
(
    [0] => Array 
     (
      [0] => [email protected] 
      [1] => [email protected] 
      [2] => [email protected] 
      [3] => [email protected] 
      [4] => [email protected] 
      [5] => [email protected] 
      [6] => [email protected] 
      [7] => [email protected] 
     ) 

) 

如何去解決它?

+1

是該數據是從使用SQL表中拉回來?如果這樣,那麼問題就不能在那裏解決了? (一羣一羣)只接受獨特的答覆? – Aleski 2012-04-25 12:25:59

+1

嘗試在php – Prabhuram 2012-04-25 12:26:04

回答

7

嘗試array_unique

代碼:

<?php 

$arr = array_unique($arr); 

?> 

陣列array_unique(數組$陣列[摘要$ sort_flags改變= SORT_STRING ])

採用輸入數組並返回一個新的沒有重複值的數組。

+0

中使用array_unique並且僅供參考,['array_unique' docs](http://php.net/manual/en/function.array-unique.php) – 2012-04-25 12:26:39

3
嘗試

array_unique()

$newArray = array_unique($oldArray); 

從文檔:

[array_unique()]拍攝的輸入陣列和返回而不重複值的新數組。

0

沒有array_unique()解決方案。沒有那麼聰明:)

array_keys(array_flip($array)); 

如果使用數組,$array = $yourArray[0];