![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.php archiveLooping through arrays with foreach
From: Sjoerd <sjoerder@gmail.com>
Date: Fri Mar 31 2006 - 12:29:42 CEST
Summary: Use foreach(..) instead of while(list(..)=each(..)).
--=[ How to use foreach ]=--
Foreach is a language construct, meant for looping through arrays.
foreach (array_expression as $value)
For example:
This will output:
--=[ Why not to use list & each ]=--
Another method to loop through an array is the following:
This has some disadvantages:
--=[ About for & count ]=--
Another method to loop through an array:
Consider this array:
The above for-loop would loop from elements 0 through 5, while
|