Array_unique () Definition and usage
The Array_unique () function shifts the duplicate values in the divisor group and returns an array of results.
When the values of several array elements are equal, only the first element is preserved and the other elements are deleted.
The key name in the returned array is unchanged.
Grammar
Array_unique (Array)
Parameter description
Array required. A specified array of inputs.
Description
Array_unique () First sorts the value as a string, and then only the first encountered key name for each value is kept, followed by all subsequent key names. This does not mean that the first occurrence of the same value in the unsorted array will be preserved.
Tips and comments
Note: The returned array retains the key type of the first array element.
Example
Copy Code code as follows:
<?php
$a =array ("a" => "cat", "B" => "Dog", "C" => "cat");
Print_r (Array_unique ($a));
?>
Output:
Array ([a] => Cat [b] => Dog)