For
The For loop is a very complex loop in PHP. It behaves as if it were in the C language. The following is the syntax for looping:
for (EXPR1; expr2; expr3) statement
The first expression (EXPR1) is the value of the loop's unconditional start.
At each iteration, the expression expr2 is computed. If the value is true, the loop continues, executing the nested statement. If the value is false, the execution of the loop after the
At each iteration, the expression EXPR3 is computed (executed).
Each expression can be empty. EXPR2 null means that the loop will run indeterminate (PHP implicitly thinks it is true, like C). It's not going to end like you think, you can use the Web site Building server script Class \phpphp user manual Fancycontrol-structures.break.html>break statement to replace the for fact expression to end the loop.
Consider the following example. They will show numbers from 1 to 10:
/* Example 1 */for ($i = 1; $i <=; $i + +) {print $i;} /* Example 2 */for ($i = 1;; $i + +) {if ($i >) {break;} print $i;} /* Example 3 */$i = 1;for (;;) {if ($i >) {break;} print $i; $i + +;} /* Example 4 */for ($i = 1; $i <=; print $i, $i + +);
Of course, from the first example, it is abbreviated (or fourth), but you can see that there are a lot of opportunities for you to use an empty expression.
PHP still supports the "colon syntax" of loops.
for (EXPR1; expr2; expr3): statement; ...; ENDfor;
Another my language has a foreach statement to manipulate arrays or hashes. There is no such construct in PHP 3; PHP 4 is (see foreach). In PHP 3, people can use the while, List (), and each () functions to do the same thing. See the documentation for these functions.
http://www.bkjia.com/PHPjc/532350.html www.bkjia.com true http://www.bkjia.com/PHPjc/532350.html techarticle The for-for loop is a very complex loop in PHP. It behaves as if it were in the C language. The following is the syntax of the loop: for (EXPR1; expr2; expr3) statement the first expression (EXPR1) is a loop ...