php multi-dimensional array remove duplicate [duplicate]

A quick solution which uses the uniqueness of array indexes:

$newArr = array();
foreach ($array as $val) {
    $newArr[$val[2]] = $val;    
}
$array = array_values($newArr);

Notice 1: As visible from above, the last match for an email address is used instead of the first. This can be changed by replacing the second line with

foreach (array_reverse($array) as $val) {

Notice 2: The indexes in the resulting array are somewhat mixed up. But I guess this doesn’t matter…

Leave a Comment