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()
我想计算差异的数量,有没有更快的方法?我做错了什么?
count(array_diff_assoc($array1, $array2));
$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;
这应该适合你。
您可以使用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
?>