Problem:
You have a multidimensional array with subarrays containing name, surname, and email information, as shown below:
$array = [ [0] => ['dave', 'jones', 'dave.jones@example.com'], [1] => ['john', 'jones', 'john.jones@example.com'], [2] => ['bruce', 'finkle', 'bruce.finkle@example.com'], ];
You need to remove duplicate subarrays based on the email value.
Solution:
To effectively deduplicate a multidimensional array based on a specific value, we can utilize array indexes' uniqueness. Here's a solution using this approach:
$newArr = []; foreach ($array as $val) { $newArr[$val[2]] = $val; } $array = array_values($newArr);
Notice:
foreach (array_reverse($array) as $val) {
The above is the detailed content of How to Remove Duplicate Subarrays from a PHP Multidimensional Array Based on Email?. For more information, please follow other related articles on the PHP Chinese website!