note 127305 added to function.array-diff-assoc

From: Date: Tue, 19 Jul 2022 13:53:26 +0000
Subject: note 127305 added to function.array-diff-assoc
Groups: php.notes 
Request: Send a blank email to php-notes+get-219036@lists.php.net to get a copy of this message
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) } ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.135 (proxied: 109.251.121.9) ---- Manual Page -- https://php.net/manual/en/function.array-diff-assoc.php Edit -- https://main.php.net/note/edit/127305 Del: integrated -- https://main.php.net/note/delete/127305/integrated Del: useless -- https://main.php.net/note/delete/127305/useless Del: bad code -- https://main.php.net/note/delete/127305/bad+code Del: spam -- https://main.php.net/note/delete/127305/spam Del: non-english -- https://main.php.net/note/delete/127305/non-english Del: in docs -- https://main.php.net/note/delete/127305/in+docs Del: other reasons-- https://main.php.net/note/delete/127305 Reject -- https://main.php.net/note/reject/127305 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#219036) next »