Doc #69059 [Fbk]: array_udiff logical bug

From: Date: Mon, 16 Feb 2015 03:38:53 +0000
Subject: Doc #69059 [Fbk]: array_udiff logical bug
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-11949@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69059&edit=1 ID: 69059 Updated by: laruence@php.net Reported by: geoleu11 at gmail dot com Summary: array_udiff logical bug Status: Feedback Type: Documentation Problem Package: *General Issues Operating System: Ubuntu PHP Version: Irrelevant Block user comment: N Private report: N New Comment: s ,bug,issue, Previous Comments: ------------------------------------------------------------------------ [2015-02-16 03:38:15] laruence@php.net 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 ------------------------------------------------------------------------ [2015-02-16 01:03:04] 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) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69059&edit=1

« previous php.doc.bugs (#11949) next »