php: array_diff_assoc and the order of parameters
published 11 April 2007
This took a while till I found out: They actually do matter!
Even worse: The manual says so!!!! Just that I was to stupid to read it.
Lesson learned. No more guessing, no more quick reading!
<?
$a = array(
'x' => 'x',
'y' => 'y',
'z' => 'z',
't' => 't',
);
$b = array(
'x' => 'x',
'y' => 'y',
'z' => 'z',
't' => 't',
'g' => 'g',
);
print_r(array_diff_assoc($a, $b));
print_r(array_diff_assoc($b, $a));
?>
This will output:
Array
(
)
Array
(
[g] => g
)
Comment
- see http://www.php.net/manual/en/function.array-diff-assoc.php
array_diff_assoc() returns an array containing all the values from array1 that are not present in any of the other arguments.
— ShiningRay 12 April, 4:37am # - I know! Stupidity never dies, not even in oneself. However, I was assuming it would behave like a unix diff.
— Pascal Opitz 12 April, 9:57am #
Quick links
Other people's articles that we think you might be interested in:
- How To Use Valid XHTML Tags in TextMate
- 125 Social Bookmarking Sites : Importance of User Generated Tags, Votes and Links
- Email Standards Project
- Use Gmail to generate unlimited e-mail addresses
- A List Apart: Articles: Text-Resize Detection