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:
- Ajaxian » Web Inspector: Looking good, and profiling nicely
- smush it!
- cssdoc - Trac
- CSS Systems for writing maintainable CSS | Natalie Downe
- The PNG Gamma Dilemma - Trevor Morris Photographics
Want to buy a cheap laptop for your design work? read laptop reviews at laptopical.com