php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
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 :
2

4


------------------------------------------------------------2
4
6
8
0

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-22 18:44 UTC] iliaa@php.net
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 http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net 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] sniper@php.net
You should check your code..this prints same with both ways:

<?php

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

print_r($rs);

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

print_r($rs);

?>


And from manual page for array_intersect(): 
  
    "Note that keys are preserved."
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jul 06 03:01:28 2020 UTC