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$arr = array(1, 4, 6, 1, 8, 9, 4, 6);
2
3$unique = array_unique($arr);
4
5$duplicates = array_diff_assoc($arr, $unique);
6
7print_r($duplicates);
8Array ( [3] => 1 [6] => 4 [7] => 6 )
1function has_dupes($array) {
2 $dupe_array = array();
3 foreach ($array as $val) {
4 if (++$dupe_array[$val] > 1) {
5 return true;
6 }
7 }
8 return false;
9}