Definition and Usage
The array_unique() function removes duplicate values from an array. If two or more array values are the same, the first appearance will be kept and the other will be removed.Syntax
array_unique(array)
| Parameter | Description |
|---|---|
| array | Required. Specifying an array |
Tips and Notes
Note: The returned array will keep the first array item's key type.Example
<?php
$a=array("a"=>"Cat","b"=>"Dog","c"=>"Cat");
print_r(array_unique($a));
?>
$a=array("a"=>"Cat","b"=>"Dog","c"=>"Cat");
print_r(array_unique($a));
?>
Array ( [a] => Cat [b] => Dog )