Source:
$b)? 1:-1; } $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "green", "yellow", "red"); $result = array_diff_uassoc($array1, $array2, "key_compare_func"); print_r($result);
Results:
string(1) "b"string(1) "a"=====1string(1) "b"string(1) "c"=====2int(0)string(1) "b"=====3string(1) "a"int(0)=====4int(0)string(1) "a"=====5int(1)int(0)=====6string(1) "a"int(0)=====7string(1) "a"string(1) "a"=====8int(0)string(1) "a"=====8int(0)int(0)=====9string(1) "b"string(1) "a"=====9string(1) "b"int(0)=====10string(1) "b"int(1)=====11string(1) "c"string(1) "a"=====12string(1) "c"int(0)=====13string(1) "c"int(1)=====14Array( [b] => brown [c] => blue [0] => red)
Excuse me:
对于这个函数,他的比较原理是什么?为什么要进行14次比较?
Reply content:
Source:
$b)? 1:-1; } $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); $array2 = array("a" => "green", "yellow", "red"); $result = array_diff_uassoc($array1, $array2, "key_compare_func"); print_r($result);
Results:
string(1) "b"string(1) "a"=====1string(1) "b"string(1) "c"=====2int(0)string(1) "b"=====3string(1) "a"int(0)=====4int(0)string(1) "a"=====5int(1)int(0)=====6string(1) "a"int(0)=====7string(1) "a"string(1) "a"=====8int(0)string(1) "a"=====8int(0)int(0)=====9string(1) "b"string(1) "a"=====9string(1) "b"int(0)=====10string(1) "b"int(1)=====11string(1) "c"string(1) "a"=====12string(1) "c"int(0)=====13string(1) "c"int(1)=====14Array( [b] => brown [c] => blue [0] => red)
Excuse me:
对于这个函数,他的比较原理是什么?为什么要进行14次比较?
Check the source code, before the comparison, PHP also carried out a sort operation, sorting will also take the callback function, which is what you will see in the results b
and c
the two appear in the same array of keys to compare the records.