php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20319 array_diff error with array contain NULL values.
Submitted: 2002-11-08 14:36 UTC Modified: 2002-11-10 16:34 UTC
From: yanik at lecourriel dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.2 OS: Linux RedHat
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: yanik at lecourriel dot com
New email:
PHP Version: OS:

 

 [2002-11-08 14:36 UTC] yanik at lecourriel dot com
This work !!!
------------------------------------------------
$arr1 = array('Color' => '');
$arr2 = array('Img1' => 3, 'Img2' => 2, 'Color' => 'Yellow');
print_r(array_diff($arr1, $arr2));

Return : Array ( [Color] => ) 

This not work!!!
------------------------------------------------
$arr1 = array('Color' => '');
$arr2 = array('Img1' => NULL, 'Img2' => 2, 'Color' => 'Yellow');
print_r(array_diff($arr1, $arr2));

Return : Array () 

This work !!!
------------------------------------------------
$arr1 = array('Color' => 'Red');
$arr2 = array('Img1' => NULL, 'Img2' => 2, 'Color' => 'Yellow');
print_r(array_diff($arr1, $arr2));


When your array contain NULL value the array diff does not recognize that Color is different. But if "Color" is not empty and different in both array the return value is corect.

Sorry for my english !

Yanik

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-10 16:34 UTC] venaas@php.net
In PHP '' == NULL, so I think it's correct that array_diff()
treats them the same. It removes all elements from the 1st
argument that are equal (normal PHP equality) to any element
in the other arguments.

 [2016-01-22 09:37 UTC] andrius dot vs at gmail dot com
Problem with empty elements in array with array_diff

$arr1 = array( [10] =>,[218] =>, [219] =>, [222] =>);
$arr2 = array( [10] =>disturbing Stuff,[218] =>, [219] =>, [222] => 45);
print_r(array_diff($arr1, $arr2));

Return : Array ()
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Jan 21 08:01:23 2020 UTC