Regardless what others are offering here, you are looking for a function called array_unique
Docs. The important thing here is to set the second parameter to SORT_REGULAR
and then the job is easy:
array_unique($result, SORT_REGULAR);
The meaning of the SORT_REGULAR
flag is:
compare items normally (don't change types)
And that is what you want. You want to compare arraysDocs here and do not change their type to string (which would have been the default if the parameter is not set).
array_unique
does a strict comparison (===
in PHP), for arrays this means:
$a === $b
TRUE
if $a and $b have the same key/value pairs in the same order and of the same types.
Output (Demo):
Array
(
[0] => Array
(
[a] => 1
[b] => Hello
)
[1] => Array
(
[a] => 1
[b] => other
)
)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…