|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42838 Wrong results in array_diff_uassoc (php 5.2.3)
Submitted: 2007-10-03 14:21 UTC Modified: 2009-07-09 20:38 UTC
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: tchunai at ig dot com dot br Assigned: felipe (profile)
Status: Closed Package: Arrays related
PHP Version: 5.2.4 OS: Windows
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: tchunai at ig dot com dot br
New email:
PHP Version: OS:


 [2007-10-03 14:21 UTC] tchunai at ig dot com dot br

    If in both array's of comparison will have some key 0 (zero), the same it is discarded and enclosed as different in the return of 'array_diff_uassoc'.

Reproduce code:
    function key_compare_func($a, $b)
        if ($a === $b) {
            return 0;
        return ($a > $b)? 1:-1;

    $array1 = array("a" = "green", "b" = "Brown", "c" = "blue", 0 = "red");
    $array2 = array("a" = "green", "b" = "Brown", "c" = "blue", 0 = "red");
    $result = array_diff_uassoc($array1, $array2, "key_compare_func");

Expected result:

Actual result:
        [b] = brown
        [c] = blue
        [0] = red


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-03 15:59 UTC]
What do you mean with the 'php 5.2.3' in your summary? Do you mean you're using 5.2.3 and not 5.2.4? Or did it work in 5.2.3?
 [2007-10-03 20:52 UTC] tchunai at ig dot com dot br

I am using 5.2.3.

Best regards
 [2007-10-05 15:30 UTC]
Seems to happen with later versions too.
 [2007-10-05 15:31 UTC]
Assigned to the author of this (and the other similar) function.
 [2008-01-25 02:53 UTC]
Also verified with PHP 5.2.5 on a Linux environment.
 [2008-02-14 14:04 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

 [2009-07-01 15:34 UTC]
The fix causes enormous slowdown.
See #47643
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Apr 13 17:01:24 2021 UTC