#33854 [Opn->Bgs]: array_diff depending on element sequence
| From: | iliaa@php.net | Date: | Mon, 25 Jul 2005 20:32:45 +0000 |
| Subject: | #33854 [Opn->Bgs]: array_diff depending on element sequence | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-82423@lists.php.net to get a copy of this message | ||
ID: 33854
Updated by: iliaa@php.net
Reported By: bob dot siefkes at packardbell dot com
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: XP SP2
PHP Version: 5.0.4
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
if you want keys & position to be considered use the array_diff_assoc()
function.
Previous Comments:
------------------------------------------------------------------------
[2005-07-25 21:26:16] bob dot siefkes at packardbell dot com
I did confuse the two result blocks...
Expected result: <--> Actual result:
------------------------------------------------------------------------
[2005-07-25 21:23:22] bob dot siefkes at packardbell dot com
Description:
------------
Behavor of array_diff is dependent on the sequence of the elements in
the array.
See $array2 where I changed the sequence of "a"=>"c" with
"a"=>"d" and
it results in different output.
Be noted that the key of both elements is the same, still I would not
expect array_diff to take this into account.
Bob
Reproduce code:
---------------
// source 1
$array1 = array("a" => "c", "b" => "b" );
$array2 = array("a" => "c", "a" => "d" );
$result = array_diff($array1, $array2);
// source 2
$array1 = array("a" => "c", "b" => "b" );
$array2 = array("a" => "d", "a" => "c" );
$result = array_diff($array1, $array2);
Expected result:
----------------
// result1:
Array
(
[a] => c
[b] => b
)
// result2
Array
(
[b] => b
)
Actual result:
--------------
// for both I would expect
Array
(
[b] => b
)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33854&edit=1