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
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 00:01:41 2024 UTC