1, the Process Control statements mainly have if, ii...else, ElseIf (sometimes can also be written as else if), switch four kinds. The statement format in PHP is:
if (condition satisfied) {EXECUTE statement}
if (condition satisfied) {EXECUTE statement} else {EXECUTE statement}
if (condition satisfied) {EXECUTE statement} ElseIf {EXECUTE statement} ElseIf {EXECUTE statement} ... else {EXECUTE statement}
Switch (condition) {Case 1: statement; break;
Case 2: statement; break;
Case 3: statement; break;
Default: statement; break;}
if: Condition only one
If...else: There are two conditions
ElseIf: Conditions have multiple
SWITCH: Conditional multiple When the condition is multiple, ElseIf is the same as the switch statement. But to avoid lengthy statements, use the switch statement
2, the loop control statement mainly has while, for, do and three kinds. For example, to output all integers less than 5, the format of the statement in PHP is:
While statement ******* $i = 0; while ($i <5) {echo $i; $i + +; } *******for statement ******* for ($i = 0; $i < 5; $i + +) {echo $i; } ******do while statement ******* $i = 0; do {echo $i; $i + +; }while ($i <5);
Note
1, while loop implementation does not know the number of cycles, for loop known number of cycles.
2, in a complex PHP code, may contain a number of conditional control statements, loop control statements and functions, find matching curly braces "{}" very cumbersome. To do this, PHP provides a different writing format, including if, while, for, foreach, and switch can be used. The basic form of writing this form is to use the colon ":" instead of the left brace "{", using endif, Endwhile, ENDfor, Endforeach, Endswitch; to replace the curly brace "}" on the right.
"keywords"
Break: Terminate Loop
Continue: Terminates this cycle and continues the next loop until the end of the loop