Being a multidimensional array, you must iterate through the list or employ a callback function to array_filter. The two should perform nearly the same efficiency wise, so that is not of issue.
<?php
$sampledata = array(
array(".id" => "*1", "name" => "ali"),
array(".id" => "*2", "name" => "ali"),
array(".id" => "*3", "name" => "ali"),
array(".id" => "*4", "name" => "john"),
array(".id" => "*5", "name" => "john"),
);
function array_filter_callback($array) {
global $names;
$name = $array['name'];
if(isset($names[$name])) {
return false;
} else {
$names[$name] = 1;
return true;
}
}
$names = array();
$filtered_array = array_filter($sampledata, "array_filter_callback");
print_r($filtered_array);Array
(
[0] => Array
(
[.id] => *1
[name] => ali
)
[3] => Array
(
[.id] => *4
[name] => john
)
)This will essentially store all names in a global array, if the name is already in the array then the entry will be filtered out (by returning
false to array_filter's callback result.)
Be sure to read the updated
FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us
why or
what errors occurred.