Bug #20319 [Com]: array_diff error with array contain NULL values.

From: Date: Fri, 22 Jan 2016 09:37:09 +0000
Subject: Bug #20319 [Com]: array_diff error with array contain NULL values.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-198834@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=20319&edit=1 ID: 20319 Comment by: andrius dot vs at gmail dot com Reported by: yanik at lecourriel dot com Summary: array_diff error with array contain NULL values. Status: Not a bug Type: Bug Package: Arrays related Operating System: Linux RedHat PHP Version: 4.2.2 Block user comment: N Private report: N New Comment: 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 () Previous Comments: ------------------------------------------------------------------------ [2002-11-10 16:34:20] 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. ------------------------------------------------------------------------ [2002-11-08 14:36:00] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=20319&edit=1

« previous php.bugs (#198834) next »