|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 17:00:02 2025 UTC |
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."