array_unique() Definition and Usage
array_unique() function removes duplicate values from an array and returns the resulting array.
When the values of several array elements are equal, only the first element is retained and the other elements are deleted.
The key names in the returned array remain unchanged.
Syntax
array_unique(array)
Parameter Description
array Required. Specifies the input array.
Description
array_unique() first sorts the values as strings, then only retains the first encountered key name for each value, and then ignores all subsequent key names. This does not mean that the first occurrence of the same value in an unsorted array will be preserved.
Tips and Notes
Note: The returned array will retain the key type of the first array element.
Example
Copy code The code is as follows:
$a=array("a"=>"Cat","b"=>"Dog","c"= >"Cat");
print_r(array_unique($a));
?>
The above has introduced the PHP array function sequence array_unique - removing duplicate element values in the array, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.