Re: Looping through arrays with foreach
- From: Oli Filth <catch@xxxxxxxxxxxxxx>
- Date: Fri, 31 Mar 2006 10:40:34 GMT
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
.
- References:
- Looping through arrays with foreach
- From: Sjoerd
- Looping through arrays with foreach
- Prev by Date: Looping through arrays with foreach
- Next by Date: Re: syndicating content
- Previous by thread: Looping through arrays with foreach
- Next by thread: Re: Looping through arrays with foreach
- Index(es):