Array_unique () Definition and usage
The array_unique () function removes repeated values from the array and returns the result array.
When the values of several array elements are equal, only the first element is retained, and other elements are deleted.
The Input key of the returned array remains unchanged.
Syntax
Array_unique (array)
Parameter description
Array is required. Specifies the input array.
Description
Array_unique () First sorts the values as strings, then retains only the first key name that is encountered for each value, and then ignores all the key names that follow. This does not mean that the first key name that appears for the same value in the unordered array will be retained.
Tips and comments
Note: The returned array retains the key type of the first array element.
Example
Copy codeThe Code is as follows:
<? Php
$ A = array ("a" => "Cat", "B" => "Dog", "c" => "Cat ");
Print_r (array_unique ($ ));
?>
Output:
Array ([a] => Cat [B] => Dog)