hax0r hax0r - 3 months ago 6
PHP Question

Removing duplicated values from two-dimensional array

I want to remove duplicated values from two-dimensional array.
I have used "array_unique" function to the two-dimensional array. And it seems that this function does not work for two-dimensional array.
Any suggestion or help would be appreicated.
Thank you in advance.

Here is my array output below:

Array
(
[0] => Array
(
[Is_Hide] => 0
[Key] => LHo0VTLsFcI7wWq2EWQy1nUp5U13pXWLXt8s0775
)

[1] => Array
(
[Is_Hide] => 0
[Key] => GiSKlOZXRhXTmHKLAeEMPUWoJMs08ftWeenCMrPk
)

[2] => Array
(
[Is_Hide] => 0
[Key] => LHo0VTLsFcI7wWq2EWQy1nUp5U13pXWLXt8s0775
)
)

Answer

You can use PHP's array_map() function:

$input = array_map("unserialize", array_unique(array_map("serialize", $input)));

See this example.