比较php中两个数组的差异

Array ( [34] => A [35] => B [36] => B [37] => C ) //This is the Answer

Compares

Array ( [34] => B [35] => C [36] => A [37] => D ) //This is the right data

I have tried array_diff_key and array_diff functions but both only returns

Array()

I would like to get the count of the difference, is there a faster way?

What did i do wrong? Thank you very much for your help!

count(array_diff_assoc($array1, $array2));

You can use 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

?>

Demo: http://codepad.org/Zzilrn9C

$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;

This should work for you.