Der folgende Code entfernt alle doppelten Elemente aus einem mehrdimensionalen Array. Der strukturelle Aufbau spielt dabei keine Rolle.
Code:
/* Vorher:
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)));
/* Nachher:
Array
(
[0] => Array ( [0] => unique )
[1] => Array
(
[0] => Array ( [0] => 1337 )
[1] => Array ( [0] => 1338 )
)
[3] => Array ( [test] => test )
[5] => Array ( [0] => 123456 )
)
*/
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)));
/* Nachher:
Array
(
[0] => Array ( [0] => unique )
[1] => Array
(
[0] => Array ( [0] => 1337 )
[1] => Array ( [0] => 1338 )
)
[3] => Array ( [test] => test )
[5] => Array ( [0] => 123456 )
)
*/