1
2<?php
3$input = array("a" => "green", "red", "b" => "green", "blue", "red");
4$result = array_unique($input);
5print_r($result);
6?>
7
8Array
9(
10 [a] => green
11 [0] => red
12 [1] => blue
13)
1<?php
2 // Syntax: array_unique(array $array, int $flags = SORT_STRING): array
3 // Desc: Removes duplicate values from an array
4 $arr = Array("red", "red", "green", "blue", "blue", "white");
5 echo "<pre>";
6 print_r($arr);
7 echo "</pre> <br><br>";
8
9 $arrUnique = array_unique($arr);
10
11 echo "<pre>";
12 print_r($arrUnique);
13 echo "</pre> <br><br>";
14
15 /* -------- output -----------
16 Array
17 (
18 [0] => red
19 [1] => red
20 [2] => green
21 [3] => blue
22 [4] => blue
23 [5] => white
24 )
25
26 Array
27 (
28 [0] => red
29 [2] => green
30 [3] => blue
31 [5] => white
32 )
33 */
34?>