PHP 关联键区分大小写,键 "a" 与键 "A" 不同
<?php
$arr = ["A" => 666];
var_dump($arr["a"]);
var_dump($arr["A"]);
?>
产生
NULL
int(666)
同样地,array_diff_assoc 区分大小写地处理键,键 "A" 不等于键 "a" 并且会被 diff
<?php
$compareWhat = ["a" => 666, "b" => 666, "c" => 666, ];
$compareWith = ["A" => 666, "b" => 667, "c" => 666, ];
var_dump(array_diff_assoc($compareWhat, $compareWith));
?>
产生
array(2) {
["a"]=> int(666)
["b"]=> int(666)
}
如果数组中值的顺序不同,结果的顺序也会不同,尽管本质上结果保持不变。
<?php
$compareWhat = ["b" => 666, "a" => 666, "c" => 666, ];
$compareWith = ["A" => 666, "b" => 667, "c" => 666, ];
var_dump(array_diff_assoc($compareWhat, $compareWith));
?>
产生
array(2) {
["b"]=> int(666)
["a"]=> int(666)
}