Voting

: nine minus four?
(Example: nine)

The Note You're Voting On

nekto
2 years ago
PHP associative keys are case-sensitive, key "a" is different from key "A":

<?php
$arr
= ["A" => 666];
var_dump($arr["a"]);
var_dump($arr["A"]);
?>

produces:
NULL
int(666)

And in the same way, array_diff_assoc treats keys case-sensitively, and key "A" is not equal to key "a" and will be diffed:

<?php
// in arrays below value of "a" and "A" are the same, but keys are different
// values of "b" are different
// values of "c" are the same
$compareWhat = ["a" => 666, "b" => 666, "c" => 666, ];
$compareWith = ["A" => 666, "b" => 667, "c" => 666, ];

var_dump(array_diff_assoc($compareWhat, $compareWith));
?>

produces:
array(2) {
["a"]=> int(666)
["b"]=> int(666)
}

And if the order of values in array is different, the order of the result will be different, although essentially the result stays the same:

<?php
// the same as above, but "b" comes before "a" in $compareWhat
$compareWhat = ["b" => 666, "a" => 666, "c" => 666, ];
$compareWith = ["A" => 666, "b" => 667, "c" => 666, ];

var_dump(array_diff_assoc($compareWhat, $compareWith));
?>

produces:
array(2) {
["b"]=> int(666)
["a"]=> int(666)
}

<< Back to user notes page

To Top