$array = array('a',2 ,2 ,1 ,3);
if (count($array) != count(array_unique($array))) echo 'there are the same values in the array';这样可以判断是否有重复?但是要找到重复的键值要怎么写呢?
if (count($array) != count(array_unique($array))) echo 'there are the same values in the array';这样可以判断是否有重复?但是要找到重复的键值要怎么写呢?
说明
array array_count_values ( array input )
array_count_values() 返回一个数组,该数组用 input 数组中的值作为键名,该值在 input 数组中出现的次数作为值。
你只要遍历返回数组,打印值是2?或者随你,重复多少次的元素即可全部功能复杂度是O(n),所以元素多一些并不可怕