Array ( [34] => A [35] => B [36] => B [37] => C ) //This is the Answer
比较
Array ( [34] => B [35] => C [36] => A [37] => D ) //This is the right data
我尝试了array_diff_key
和array_diff
功能,但两者都只返回
Array()
我想得到差异的数量,是否有更快的方式?
我做错了什么?非常感谢你的帮助!
答案 0 :(得分:4)
count(array_diff_assoc($array1, $array2));
答案 1 :(得分:0)
您可以使用array_diff_assoc()。
<?php
$array1 = array('34' => 'A', '35' => 'B', '36' => 'B', '37' => 'C');
$array2 = array('34' => 'B', '35' => 'C', '36' => 'A', '37' => 'D');
$count = count(array_diff_assoc($array1, $array2));
echo $count; //4
?>
答案 2 :(得分:0)
$array1 = array ( [34] => A [35] => B [36] => B [37] => C )
$array2 = array( [34] => B [35] => C [36] => A [37] => D )
$c = count(array_diff($array1, $array2));
echo $c;
这应该适合你。