<?php
$list_programming_language = array('C#', 'C++', 'PHP', 'C#', 'PHP');
$result = array_unique($list_programming_language);
print_r($result);
?>
// ==> 'C#', 'C++', 'PHP'
$serialized = array_map('serialize', $targetArray);
$unique = array_unique($serialized);
return array_intersect_key($targetArray, $unique);
array_unique($array, SORT_REGULAR);
<?php
$fruits_list = array('Orange', 'Apple', ' Banana', 'Cherry', ' Banana');
$result = array_unique($fruits_list);
print_r($result);
?>
We used this to de-duplicate results from a variety of overlapping queries.
$input = array_map("unserialize", array_unique(array_map("serialize", $input)));
<?php
$unique_ids = array_count_values(array_column($array,'id'));
$res = array_filter($array, fn($v) => $unique_ids[$v['id']] === 1);
print_r($res);
function _unique($array, $key) {
$temp_array = array();
foreach($array as $v) {
if (!isset($temp_array[$v[$key]]))
$temp_array[$v[$key]] = $v;
}
$array = array_values($temp_array);
return $array;
}