Bug #61540 [Com]: array_diff has problem when in second array is entry with null value
| From: | reeze dot xia at gmail dot com | Date: | Thu, 29 Mar 2012 04:24:54 +0000 |
| Subject: | Bug #61540 [Com]: array_diff has problem when in second array is entry with null value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-168949@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=61540&edit=1
ID: 61540
Comment by: reeze dot xia at gmail dot com
Reported by: pfraszczak at power dot com dot pl
Summary: array_diff has problem when in second array is entry
with null value
Status: Open
Type: Bug
Package: Arrays related
Operating System: ubuntu
PHP Version: 5.3.10
Block user comment: N
Private report: N
New Comment:
Hi pfraszczak:
This is NOT a bug.
because "" == NULL => TRUE.
if we change the test script to :
$a =
array('street'=>'not-null-equal-value','number'=>'n1');
$b =
array('street'=>'b1','number'=>'n1','test'=>null);
var_dump(array_diff($a,$b));
you will get the right result.
Previous Comments:
------------------------------------------------------------------------
[2012-03-28 10:27:18] pfraszczak at power dot com dot pl
Changed package
------------------------------------------------------------------------
[2012-03-28 10:23:25] pfraszczak at power dot com dot pl
Description:
------------
I notice that array_diff return empty array when in second array we have entry with null value. When
i removed entry with test key - everything works fine.
Moreover it seems that null values in $a array don't brake array_diff
Test script:
---------------
$a = array('street'=>'','number'=>'n1');
$b =
array('street'=>'b1','number'=>'n1','test'=>null);
var_dump(array_diff($a,$b));
Expected result:
----------------
array(1) {
["street"]=>
string(0) ""
}
Actual result:
--------------
array(0) {
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=61540&edit=1