Remove duplicate entries in a mulitdimensional array
Snippet for removing duplicate entries in a multidimensional array
/* Before:
Array
(
[0] => Array ( [0] => unique )
[1] => Array
(
[0] => Array ( [0] => 1337 )
[1] => Array ( [0] => 1338 )
)
[2] => Array
(
[0] => Array ( [0] => 1337 )
[1] => Array ( [0] => 1338 )
)
[3] => Array ( [test] => test )
[4] => Array ( [test] => test )
[5] => Array ( [0] => 123456 )
[6] => Array ( [0] => 123456 )
)
*/
$aArray = array_map("unserialize", array_unique(array_map("serialize", $aArray)));
/* After:
Array
(
[0] => Array ( [0] => unique )
[1] => Array
(
[0] => Array ( [0] => 1337 )
[1] => Array ( [0] => 1338 )
)
[3] => Array ( [test] => test )
[5] => Array ( [0] => 123456 )
)
*/
Url: http://sklueh.de/2012/11/php-doppelte-elemente-aus-einem-mehrdimensionalen-array-entfernen/
Language: PHP | User: sklueh | Created: Sep 24, 2013 | Tags: array_map duplicate array array_unique