The array_unique() is used to remove duplicate values from an array.
Note: The keys are preserved. array_unique() sorts the values treated as a string at first, then will keep the first key encountered for every value, and ignore all following keys. It does not mean that the key of the first related value from the unsorted array will be kept.
Parameter | Description |
---|---|
array | Required. Specifying an array |
sortingtype | Optional. Specifies how to compare the array elements/items. Possible values:
|
Syntax
array_unique(array)
Example
$array = array("a"=>"Cooper","b"=>"Samuel","c"=>"Cooper", "d"=>"Cooper");
print_r(array_unique($array));
Output
Array ( [a] => Cooper [b] => Samuel )