|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #11338 arraydiff returns a vector with "empty" values for found values
Submitted: 2001-06-07 16:07 UTC Modified: 2001-09-14 19:25 UTC
From: Jean-Pierre dot Malisse at mumm dot ac dot be Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.0.5 OS: True64Unix 5.1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: Jean-Pierre dot Malisse at mumm dot ac dot be
New email:
PHP Version: OS:


 [2001-06-07 16:07 UTC] Jean-Pierre dot Malisse at mumm dot ac dot be

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 *  !!  

   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

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 

   echo "2>",$olang[0],"*",$olang[1],"#",$olang[2],"\n";



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-14 19:25 UTC]
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) {
  string(1) "b"
array(1) {
  string(1) "b"

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Oct 23 09:03:33 2021 UTC