1<?php
2$fruits_list = array('Orange', 'Apple', ' Banana', 'Cherry', ' Banana');
3$result = array_unique($fruits_list);
4print_r($result);
5?>
6
7Output:
8
9Array ( [0] => Orange [1] => Apple [2] => Banana [3] => Cherry )
1<?php
2 function super_unique($array,$key)
3 {
4 $temp_array = [];
5 foreach ($array as &$v) {
6 if (!isset($temp_array[$v[$key]]))
7 $temp_array[$v[$key]] =& $v;
8 }
9 $array = array_values($temp_array);
10 return $array;
11
12 }
13
14
15$arr="";
16$arr[0]['id']=0;
17$arr[0]['titel']="ABC";
18$arr[1]['id']=1;
19$arr[1]['titel']="DEF";
20$arr[2]['id']=2;
21$arr[2]['titel']="ABC";
22$arr[3]['id']=3;
23$arr[3]['titel']="XYZ";
24
25echo "<pre>";
26print_r($arr);
27echo "unique*********************<br/>";
28print_r(super_unique($arr,'titel'));
29
30?>
31
1<?php
2$a=array("a"=>"red","b"=>"green","c"=>"red");
3print_r(array_unique($a));
4?>
5Output : Array ( [a] => red [b] => green )
6
7Example 2:
8
9
10$array = array(1, 2, 2, 3);
11$array = array_unique($array);
12Output : Array is now (1, 2, 3)
13
14
1We used this to de-duplicate results from a variety of overlapping queries.
2
3$input = array_map("unserialize", array_unique(array_map("serialize", $input)));
4