array_unique

array_unique() 函数移除数组中的重复的值,返回改变过的数组,原数组不变

这并不意味着在未排序的 array 中同一个值的第一个出现的键名会被保留,因为关联数组是无序的。


<?php $a=array("a"=>"red","b"=>"green","c"=>"red"); $b=array_unique($a));
var_dump($a);
var_dump($b) ?>
---------------------------------------------------------------
array(3) {
["a"]=>
string(3) "red"
["b"]=>
string(5) "green"
["c"]=>
string(3) "red"
}
array(2) {
["a"]=>
string(3) "red"
["b"]=>
string(5) "green"
}
 
posted @ 2018-05-31 13:16  tosee  阅读(331)  评论(0编辑  收藏  举报