I\'ve a array of associative array
array(xxx) {
[0]=>
array(3) {
[\"group_id\"]=>2
[\"contact\"]=> \"foo\"
[\"contact_email\"]=> \"fo
You can use foreach
and group them by contact_email
$r = [];
foreach($a as $v){
$r[$v['contact_email']] = $v;
}
print_r(array_values($r));// reorder index
Working example : https://3v4l.org/0oN8h
Extract to an array and index by contact_email
. Since there cannot be duplicate indexes you'll get the last occurrence:
$array = array_column($array, null, 'contact_email');
If you want to re-index that back to integers:
$array = array_values(array_column($array, null, 'contact_email'));
I think this can help
$arr = [['contact_email' => 'a@a.com'], ['contact_email' => 'a@a.com'], ['contact_email' => 'b@a.com']];
$result = [];
array_map(function ($item) use (&$result) {
$result[$item['contact_email']] = $item;
}, $arr);
print_r($result);