[prev in list] [next in list] [prev in thread] [next in thread]
List: php-doc-bugs
Subject: [DOC-BUGS] Doc #69059 [Fbk]: array_udiff logical bug
From: laruence () php ! net
Date: 2015-02-16 3:38:53
Message-ID: 201502160338.t1G3crmq021774 () sgrv20 ! php ! net
[Download RAW message or body]
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
--
PHP Documentation Bugs Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic