I have a really odd problem where if I try foreach() on an array created by file() it just returns the last element of the array. So what we have is a text file:
And this code:
$filedata = file(test.txt);
reset($filedata);
while (list($linenum, $line) = each ($filedata))
{
print "$linenum: $line";
}
print "<br>";
foreach ($filedata as $linenum => $line);
{
print "$linenum: $line";
}
And the output ends up being:
0: test1 1: test2 2: test3
2: test3
What's up with this? Am I doing something horbily wrong? I am using PHP 4.3.0 with Apache 1.3.x on Windows.