1<?php
2/**
3 Examples of these functions:
4 array_unique,
5 array_diff_assoc,
6 array_diff,
7 array_keys,
8 array_intersect
9
10 Examle with an array:
11*/
12$array = array('a', 'a', 'b', 'c', 'd');
13
14// Unique values
15$unique = array_unique($array);
16
17// Duplicates
18$duplicates = array_diff_assoc($array, $unique);
19
20// Unique values
21$result = array_diff($unique, $duplicates);
22
23// Get the unique keys
24$unique_keys = array_keys($result);
25
26// Get duplicate keys
27$duplicate_keys = array_keys(array_intersect($array, $duplicates));
28
1$arr = array(3,5,2,5,3,9);
2foreach($arr as $key => $val){
3 //remove the item from the array in order
4 //to prevent printing duplicates twice
5 unset($arr[$key]);
6 //now if another copy of this key still exists in the array
7 //print it since it's a dup
8 if (in_array($val,$arr)){
9 echo $val . " ";
10 }
11}