Bug #11338 Updated: arraydiff returns a vector with "empty" values for found values
| From: | jeroen@php.net | Date: | Fri, 14 Sep 2001 23:25:30 +0000 |
| Subject: | Bug #11338 Updated: arraydiff returns a vector with "empty" values for found values | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-65974@lists.php.net to get a copy of this message | ||
ID: 11338
Updated by: jeroen
Reported By: Jean-Pierre.Malisse@mumm.ac.be
Old Status: Open
Status: Bogus
Bug Type: Arrays related
Operating System: True64Unix 5.1
PHP Version: 4.0.5
New Comment:
Both array_diff and array_intersect preserve keys.
I don't see the problem here? array_diff and array_intersect are completely symmetric.
var_dump(array_intersect(array('a','b'), array('b')));
var_dump(array_diff (array('a','b'), array('a')));
array(1) {
[1]=>
string(1) "b"
}
array(1) {
[1]=>
string(1) "b"
}
Previous Comments:
------------------------------------------------------------------------
[2001-06-07 16:07:50] Jean-Pierre.Malisse@mumm.ac.be
Hi,
I found the following behaviour not normal....and at least not reflecting what
is said in the documentation
using arraydiff alone returns >*en#nl
there is an empty value field at the place of the "removed"
component of the array
There is an empty field between > and * !!
$lang=array("fr","en","nl");
$lg1=array("fr");
$olang=(array_diff($lang,$lg1);
echo ">",$olang[0],"*",$olang[1],"#",$olang[2],"\n";
The resulting vector is not shorter !!
1) This is not matching what is said in the documentation and can makes a
programmer loose time trying to find why it is not working as he expected,....
We would have expected a behaviour closer to array_intersect which is
returning an array with only the significant values...!
2) this is removing symetry of behaviour of array_diff compared to
array_intersect....
The following workaround solves the problem, but needs at least to CLEARLY
be mentioned in the documentation of the usage of the array_diff function,
if it would not be planned to improve the behaviour of the function in the expected
way....
$olang=array_values(array_diff($lang,$lg1));
echo "2>",$olang[0],"*",$olang[1],"#",$olang[2],"\n";
regards,
Jean-Pierre.Malisse@mumm.ac.be
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=11338&edit=1