2014-02-22 24 views
1

我想顯示數組中的所有數據,但除了重複的數據外。使用PHP刪除數組中的重複值

我的數組是這樣的:

array (size=4) 
     0 => string 'Eclairage Public' (length=16) 
     1 => string 'Fonte de Voirie' (length=15) 
     2 => string 'Aire de jeux' (length=12) 
     3 => string 'Aire de jeux' (length=12) 
     4 => string 'Fonte de Voirie' (length=15) 

我想這隻能說明:

array (size=4) 
     0 => string 'Eclairage Public' (length=16) 
     1 => string 'Fonte de Voirie' (length=15) 
     2 => string 'Aire de jeux' (length=12) 

正如你所看到的,重複的元素被移除。我怎樣才能使用PHP來實現這一點?

+1

http://php.net/array_unique –

回答

1

使用​​3210。它從數組中刪除重複值。

$arr = array_unique($arr); 
+0

這個已經沒有回答過很多次了嗎?我不認爲有必要用「array_unique()'」來回答每個這樣的問題。正確的做法是將問題作爲重複投票(因爲您現在擁有簡歷權限)。 –

+0

@AmalMurali IMO,都是合適的。回答問題並將其標記爲重複。 –

+1

@BrandonWamboldt:不,沒有必要回答明顯的重複,而是投票結束。請參閱[此Meta線程](http://meta.stackexchange.com/a/10844/)。 –

0

array_unique是你在找什麼。

$array = array_unique($array); 
+0

謝謝!是工作 ... – koe