Re: Looping through arrays with foreach



Sjoerd said the following on 31/03/2006 11:29:
> Another method to loop through an array:
for ($i = 0; $i < count($arr); $i++) {
echo "value: $arr[$i]\n";
}

Consider this array:
array(5 => "Five");

The above for-loop would loop from elements 0 through 5, while
only one element exists.

Actually, no it wouldn't. count($arr) == 1, so it attempts to access only $arr[0], which clearly doesn't exist.




--
Oli
.