|
Note: This manual is provided for your convenience only - this is not the official source and may not be 100% up to date. forfor loops are the most complex loops in PHP. They behave like their C counterparts. The syntax of a for loop is:
The first expression (
In the beginning of each iteration,
At the end of each iteration,
Each of the expressions can be empty or contain multiple
expressions separated by commas. Comma separated expressions in expr2
are treated similarly to being separated by the || operator but has a
lower precedence than ||.
Consider the following examples. All of them display numbers from 1 to 10:
Of course, the first example appears to be the nicest one (or perhaps the fourth), but you may find that being able to use empty expressions in for loops comes in handy in many occasions. PHP also supports the alternate "colon syntax" for for loops. |
|