array_diff_assoc() 函數(shù)用于比較兩個(gè)數(shù)組的鍵名和鍵值,并返回差集,同時(shí)比較鍵名和鍵值。
下面是一個(gè)例子:
$array1 = array("a" => "red", "b" => "green", "c" => "blue");
$array2 = array("a" => "red", "b" => "green", "c" => "yellow");
$diff = array_diff_assoc($array1, $array2);
print_r($diff);
輸出結(jié)果為:
Array
(
[c] => blue
)
在這個(gè)例子中,兩個(gè)數(shù)組的鍵名和鍵值都進(jìn)行了比較,因此只有鍵值為 “blue” 的元素在數(shù)組1中而不在數(shù)組2中,所以輸出結(jié)果為 c => blue。