|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20032 Array_intersect function doesnt seem to work correctly
Submitted: 2002-10-22 16:26 UTC Modified: 2002-10-22 18:47 UTC
From: lalande at idbconsulting dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.3 OS: Linux Debian kernel 2.4.19
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: lalande at idbconsulting dot com
New email:
PHP Version: OS:


 [2002-10-22 16:26 UTC] lalande at idbconsulting dot com
Script :
$tab1 = array(1,2,3,4,5,6,7,8,9,0);
$tab2 = array(2,4,6,8,0);
$rs = array_intersect($tab1,$tab2);
for($i = 0; $i<sizeof($rs);$i++)
	echo $rs[$i]."<br>";
echo "<hr>";
$rs = array_intersect($tab2,$tab1);
for($i = 0; $i<sizeof($rs);$i++)
	echo $rs[$i]."<br>";

Output :



according to the documentation, array_intersect should give the same result independently of the order of parameters.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-22 18:44 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

 [2002-10-22 18:47 UTC]
You should check your code..this prints same with both ways:


$tab1 = array(1,2,3,4,5,6,7,8,9,0);
$tab2 = array(2,4,6,8,0);
$rs = array_intersect($tab1,$tab2);


$rs = array_intersect($tab2,$tab1);



And from manual page for array_intersect(): 
    "Note that keys are preserved."
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Oct 21 00:03:36 2021 UTC