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
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC