array_diff_assoc
比较两个数组的键名和键值,并返回差集
array_unique
移除数组中重复的值
array_diff
比较两个数组的键值,并返回差集
$array = array(1,2,3,3,2,1,5);$unique_arr=array_unique($array);//Array ( [0] => 1 [1] => 2 [2] => 3 [6] => 5 )$repeat_arr = array_diff_assoc ( $array, $unique_arr );print_r($repeat_arr);//Array ( [3] => 3 [4] => 2 [5] => 1 )
array_count_values
统计数组中所有值出现的次数
$array = array(1,2,3,3,2,1,5);$count_arr = array_count_values($array); foreach($count_arr as $k=>$v){ if ($v > 1){ $repeat_arr[] = $k; } }print_r($repeat_arr);//Array ( [0] => 1 [1] => 2 [2] => 3 )
来源地址:https://blog.csdn.net/weixin_43697366/article/details/127301240