PHP looping statements in detail while, for, foreach, does while
One, while loop while (expression) {loop body;//execute repeatedly until expression is false} code: $index = 1; while ($index <5) {print ' number is {$index} '; $index + +; The result of the operation: number is 1 number is 2 number is 3 number is 42, does while loop do {loop body;//execute repeatedly until expression is false} while (expression) code: do {$index + +; Print "number is {$index}";} while ($index <0); Running Result: number is 1 does while loop statement is a certain difference from while, the difference between do and whether the condition is true or not, and the while must be true before it is executed once. For a For loop, there are two types of loops depending on the loop condition: counting loops (typically using for) another: conditional loops (typically using while do-while) for (EXPR1; expr2; expr3) {statement} EX PR1 is the initial value of the condition. EXPR2 is a condition for judging, usually using the logic operation symbol (logical operators) when judging the condition. EXPR3 the part to be executed after the execution of the statement, to change the condition for the next cycle judgment, such as add one. Wait a minute. And statement is a qualifying execution part of the program, if the program has only one row, you can omit the curly brace {}. The following example is a "dare not" example written with a for loop, which can be compared with a while loop. "; } ? > Operation Result: 1. Later dared not 2. Later dared not 3. Later dared not 4. Later dared not 5. Later dared not 6. Later dared not 7. Later dared not 8. Later dared not 9. Later dared not 10. Not anymore. Four, the Foreach Loop foreach statement is used to iterate through an array. For Each loop, the value of the current array element is assigned to the value variable (the array pointer moves one at a time)-and so on: foreach (array as value) {code to be executed;} code: Operation Result: Value:one value:two value:three above is php four kinds of circulation body, according to different conditions to choose the corresponding circulation body application
http://www.bkjia.com/PHPjc/1065651.html www.bkjia.com true http://www.bkjia.com/PHPjc/1065651.html techarticle The PHP Loop statement is detailed while, for, foreach, does while a while loop while (expression) {loop body;//executes repeatedly until the expression is false} code: $index = 1; while ($index 5) {. ..