Re: Looping through arrays with foreach
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Looping through arrays with foreach

From: Oli Filth <catch@olifilth.co.uk>
Date: Fri Mar 31 2006 - 12:40:34 CEST

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
Received on Mon May 1 02:45:42 2006