array unique multidimensional array php
<?php
function super_unique($array,$key)
{
$temp_array = [];
foreach ($array as &$v) {
if (!isset($temp_array[$v[$key]]))
$temp_array[$v[$key]] =& $v;
}
$array = array_values($temp_array);
return $array;
}
$arr="";
$arr[0]['id']=0;
$arr[0]['titel']="ABC";
$arr[1]['id']=1;
$arr[1]['titel']="DEF";
$arr[2]['id']=2;
$arr[2]['titel']="ABC";
$arr[3]['id']=3;
$arr[3]['titel']="XYZ";
echo "<pre>";
print_r($arr);
echo "unique*********************<br/>";
print_r(super_unique($arr,'titel'));
?>
We used this to de-duplicate results from a variety of overlapping queries.
$input = array_map("unserialize", array_unique(array_map("serialize", $input)));
Also in PHP:
- destrroy a session php
- AWS HTTP error: SSL operation failed with code 1.
- check if string matches php
- Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://vtl-lab.com/VN/crecc-cms/api/member/register.json. (Reason: CORS request did not succeed).
- encode and decode int to base64 using php
- array push foreach php
- Y-m-d H:s:i input
- composer laravel project
- create seeder laravel
- datetimepicker format php
- array_values() in php
- check key exists in array in php
- check if id is in key array php
- datetime(today, Mtime) php
- create form request laravel
- doctrine query builder order by multiple
- base64 php
- check array has key data
- array_uniqe php
- add header to php
- empty table in laravel
- $name = $name; "Robert" echo;
- 5 examples of exception handling in php
- composer which php version