PHP unik asosiatif bersarang array berdasarkan nilai
<?php
function uniquAsoc($array,$key){
$resArray=[];
foreach($array as $val){
if(empty($resArray)){
array_push($resArray,$val);
}else{
$value=array_column($resArray,$key);
if(!in_array($val[$key],$value)){
array_push($resArray,$val);
}
}
}
return $resArray;
}
$array=[['phone'=>123,'id'=>1],['phone'=>748,'id'=>1],['phone'=>958,'id'=>3]];
print_r(uniquAsoc($array,'id'));
/*
Array
(
[0] => Array
(
[phone] => 123
[id] => 1
)
[1] => Array
(
[phone] => 958
[id] => 3
)
)
*/
?>
WebApi