Bug #63833 [Opn->Nab]: udiff doesn't compare properly inside arrays
| From: | rasmus@php.net | Date: | Sat, 22 Dec 2012 13:01:54 +0000 |
| Subject: | Bug #63833 [Opn->Nab]: udiff doesn't compare properly inside arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-175542@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63833&edit=1
ID: 63833
Updated by: rasmus@php.net
Reported by: francois dot dambrine at isen-lille dot fr
Summary: udiff doesn't compare properly inside arrays
-Status: Open
+Status: Not a bug
Type: Bug
Package: Arrays related
Operating System: Windows
PHP Version: 5.5.0alpha2
Block user comment: N
Private report: N
New Comment:
The documentation clearly states, "This function only checks one dimension of a
n-dimensional array. Of course you can check deeper dimensions by using
array_diff($array1[0], $array2[0]);."
Your example is using 2-dimensional arrays.
Previous Comments:
------------------------------------------------------------------------
[2012-12-22 12:38:38] francois dot dambrine at isen-lille dot fr
Description:
------------
This bug was introduced to me by a stackoverflow post
http://stackoverflow.com/questions/13815287/union-two-associative-array-
php/13815578#13815578 I tested the behaviour with php 5.5 Alpha 2 and the "bug" is
still there.
As of the documentation, it is said that array_diff uses an "internal function" to
compare two elements.
As equality is the only thing that matters for array_diff I thought this internal
function was something that "==" behind.
But even if two arrays are equal (same members) array_diff does not take it in
account.
I mark it as a bug but it can only be a documentation problem.
Test script:
---------------
<?php
$A = Array(
array(
'lable' =>"label0",
'id_poste'=>1,
'id_part'=>11
),
array(
'lable' =>"label1",
'id_poste'=>2,
'id_part'=>12
),
array(
'lable' =>"label2",
'id_poste'=>3,
'id_part'=>13
),
array(
'lable' =>"label3",
'id_poste'=>4,
'id_part'=>14
)
);
$B = Array(
array(
'lable' =>"label0",
'id_poste'=>1,
'id_part'=>11
),
array(
'lable' =>"label1_X",
'id_poste'=>2,
'id_part'=>12
),
array(
'lable' =>"label2",
'id_poste'=>3,
'id_part'=>13
),
array(
'lable' =>"label3_X",
'id_poste'=>4,
'id_part'=>14
)
);
var_dump(array_diff_assoc($B,$A));
Expected result:
----------------
Array(2){
[0]=>array(3){
["lable"] =>"label1_X",
["id_poste"]=>2,
["id_part"]=>12
},
[1]=>array(3){
["lable"] =>"label3_X",
["id_poste"]=>4,
["id_part"]=>14
}
}
Actual result:
--------------
array(0){
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63833&edit=1