Create multidimensional array unique for any single key index.
<?php
$users = [
['id' => 1, 'name' => 'ecortes', 'phone' => '1111111'],
['id' => 2, 'name' => 'canepa', 'phone' => '222222'],
['id' => 1, 'name' => 'john', 'phone' => '3333333'],
];
function array_unique_multi($array, $key) {
return array_reduce($array, function($acc, $curr) use($key) {
if(!in_array($curr[$key], array_column($acc, $key))) {
array_push($acc, $curr);
}
return $acc;
}, []);
}
$unique_users = array_unique_multi($users, 'id');
$users = [
['id' => 1, 'name' => 'ecortes', 'phone' => '1111111'],
['id' => 2, 'name' => 'canepa', 'phone' => '222222'],
];
?>