Latest: buggy behaviour of parent:: in PHP 5.3.3

Content with Style

Web Technique

php: array_diff_assoc and the order of parameters

by Pascal Opitz on April 12 2007, 03:55

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
)

Comments

  • 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.

    by ShiningRay on April 11 2007, 22:37 - #

  • I know! Stupidity never dies, not even in oneself. However, I was assuming it would behave like a unix diff.

    by Pascal Opitz on April 12 2007, 03:57 - #

Leave your comment

Comments are moderated.
Tags allowed: a, strong, em, code, ul, ol, li, q, blockquote, br, p

Advertisement
Advertisement