|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-03-24 18:59 UTC] pieter3d at hotmail dot com
When executing this code:
$a = array(1,2,3,4,5,6,7,8,9);
$b = array(3,4,5);
$test=array_diff($a,$b);
$i=0;
while($test[$i])
{
echo "$test[$i]<br>";
$i++;
}
the result is:
1
2
The expected result of course is
1
2
6
7
8
9
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 15:00:02 2025 UTC |
Oh well the code is bogus, actually the array returned is more like this: array(6) { [0]=> int(1) [1]=> int(2) [5]=> int(6) [6]=> int(7) [7]=> int(8) [8]=> int(9) } According to: <?php $a = array(1,2,3,4,5,6,7,8,9); $b = array(3,4,5); $test=array_diff($a,$b); $i=0; var_dump($test); ?> Keys are preserved! While just stop on your scripts because key 2 isn't defined. Don't use while for this. Not a bug, read the documentation -> Bogus.