Home >Backend Development >PHP Tutorial >php-Arrays function-array_unique-remove duplicate values in the array_PHP tutorial
array_unique() removes duplicate values in the array
【Function】
This function will return a new array without duplicate values based on the specified array, and the key names remain unchanged
This function first sorts the values as strings, and then only retains the first encountered key name for each value,
Then ignore all subsequent key names
This does not mean that the first occurrence of a key with the same value in an unsorted array is retained
【Scope of use】
php4>=4.0.1, php5.
【Use】
mixed array_unique( array array )
array/required/original array to be processed by the function
【Example】
[php]
$input=array('c'=>"green",'aed','b'=>'green','blue','bed');
var_dump(array_unique($input));
/*
array(4) {
["c"]=>
string(5) "green"
[0]=>
string(3) "aed"
[1]=>
string(4) "blue"
[2]=>
string(3) "bed"
}
*/
Excerpted from zuodefeng’s notes