#20032 [Csd->Bgs]: Array_intersect function doesnt seem to work correctly

From: Date: Tue, 22 Oct 2002 23:47:33 +0000
Subject: #20032 [Csd->Bgs]: Array_intersect function doesnt seem to work correctly
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-23075@lists.php.net to get a copy of this message
ID: 20032 Updated by: sniper@php.net Reported By: lalande@idbconsulting.com -Status: Closed +Status: Bogus Bug Type: Arrays related Operating System: Linux Debian kernel 2.4.19 PHP Version: 4.2.3 New Comment: 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." Previous Comments: ------------------------------------------------------------------------ [2002-10-22 18:44:45] 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 16:26:43] lalande@idbconsulting.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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=20032&edit=1

« previous php.bugs (#23075) next »