Remove Duplicates from PHP Multidimensional Arrays
In PHP, you can use the array_unique() function to remove duplicates in a multidimensional array. This function eliminates duplicate values and preserves the first occurrence. Here is an example code:
$multiArray = array(
array("a", "b", "c"),
array("a", "b", "c"),
array("d", "e", "f"),
array("g", "h", "i")
);
$uniqueArray = array_map("unserialize", array_unique(array_map("serialize", $multiArray)));
print_r($uniqueArray);
In the example above, we start by using the array_map() function to serialize each sub-array in the multidimensional array. Then we use the array_unique() function to remove any duplicate values in the serialized array. Finally, we use the array_map() function again to deserialize the deduplicated array and obtain the final multidimensional array $uniqueArray.