|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2015-02-16 01:03 UTC] geoleu11 at gmail dot com
 Description: ------------ --- From manual page: http://www.php.net/function.array-udiff --- Since the information that can be selected for providing php version information, here is some info about the build : PHP Version 5.5.9-1ubuntu4.5 . Also regarding the problem/bug source : array function, more specifically : array_udiff . The output of the below script is : array (size=1) 0 => string 'red' (length=3) Why does array_udiff return a common element from those arrays? Shouldn't it return the elements are present in the first array and not in the other arrays? At least if you try internal array_diff, it does return the proper value from those 2 arrays below . Test script: --------------- $a1 = array('red'); $a2 = array('red', 'blue'); $diff = array_udiff($a1, $a2, function($a, $b) { if($a === $b) { return 0; } else { return -1; } }); var_dump($diff); Expected result: ---------------- The expected result should be an empty array. array (size=0) empty Actual result: -------------- array (size=1) 0 => string 'red' (length=3) PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 22:00:01 2025 UTC | 
compare function should return value greater than 0 if $a > $b, less than 0 if $b < $a. thus, your codes should be: <?php $a1 = array('red'); $a2 = array('red', 'blue'); $diff = array_udiff($a1, $a2, function($a, $b) { if($a === $b) { return 0; } else { return $a > $b? 1 : -1; } }); var_dump($diff); anyway, this bug doesn't exists in master because new sort algo impelemented. thanks