php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37573 Wrong output for function array_diff_ukey
Submitted: 2006-05-24 05:06 UTC Modified: 2006-05-24 06:50 UTC
From: lig at maolek dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.1.4 OS: Windows XP SP2
Private report: No CVE-ID: None
 [2006-05-24 05:06 UTC] lig at maolek dot com
Description:
------------
unexpected output.  Accourding to docs array_diff_ukey "returns an array containing all the values of array1  that have keys that are not present in any of the other arguments".  A key that is present in both $array1 and $array2 is showing up in the output.  It should be noted that the values of the keys are different, but the example provided in the doc page has the same situation and the key isn't in the output.

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", "red", "");
$array2 = array("a" => "green", "yellow", "red", TRUE);
$array3 = array("red", "a"=>"brown", "");

$result[] = array_diff_ukey($array1, $array3, "key_compare_func");
$result[] = array_diff_ukey($array2, $array3, "key_compare_func");

print_r($result);

Expected result:
----------------
Array
(
    [0] => Array
        (
            [b] => brown
            [c] => blue
        )

    [1] => Array
        (
            [2] => 1
        )

)

Actual result:
--------------
Array
(
    [0] => Array
        (
            [a] => green
            [b] => brown
            [c] => blue
        )

    [1] => Array
        (
            [a] => green
            [2] => 1
        )

)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-24 06:50 UTC] tony2001@php.net
>A key that is present in both $array1 and $array2 is showing up in the output.

Of course it does.
You're comparing array1 to array3 and array2 to array3.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 07:01:27 2024 UTC