Eliminate duplicate values from an array.
<?php $a=array(“a”=>“red”,“b”=>“green”,“c”=>“red”); print_r(array_unique($a)); ?> |
The array_unique() function removes duplicate values from an array, retaining only the first occurrence of each value and discarding subsequent duplicates.
Note: The resulting array will preserve the original key types of the first occurrence.
array_unique(array, sorttype) |
Parameter |
Description |
array |
Required. Providing an array. |
sorttype |
Optional. Specifies how to compare the array elements. Possible values are:
|
Return Value: |
Returns the modified array. |
PHP Version: |
4.0.1+ |
PHP Changelog: |
PHP 7.2: When PHP 5.2.9: The default value of PHP 5.2.1: The default value of |