Overview of PHP Process Control
1, branch results (conditional structure)
One-way branch:
if (condition) {//curly braces can be followed without semicolons;
# code ...
}
Two-Way Branch
if (condition) {
# code ...
} else {
# code ...
}
Multi-Channel Branch
if (condition) {
# code ...
} elseif (condition) {//elseif can be written as else if
# code ...
} else {
# code ...
}
2, switch Multiplex branch structure
Use if structure for judging range, single value with switch
Switch (variable) {//variable with integral type and string
Case ' value1 ':
Case ' value2 '://can have multiple case
# code ...
Break If you do not break, the next case will continue to execute
Case ' Value3 ':
# code ...
Break
Default://defaults, optional
# code ...
Break
}
Second, PHP Loop statement
1, while loop
while (condition) {//First judge the condition before execution
# code ...
}
2, do While loop
Do {//First judgment condition
# code ...
while (condition); Be careful not to omit the semicolon
3, for Loop
For ($i =0 $i < $i + +) {//generally used for counting, two semicolons cannot be omitted
# code ...
}
Example: 99 multiplication table
For ($i =1 $i < $i + +) {
for ($ii =1; $ii <= $i; $ii + +) {
echo "$ii X $i =". $ii * $i. ';
}
echo "<br>";
}
Third, exit the loop statement
Exit this cycle and the next cycle will no longer be done
Break
Exit this cycle, the next cycle continues, only for the loop body (for,while,do-while)
Coninue
Completely quit the program
Exit
function executes the return value, ending the statement of the function
Return
Exit multi-tier loops
Break 1//exit current loop
Break 2//exit 2-tier loop
Continue 2
Error instances
$i = 0;
while ($i < 10) {
if ($i = = 5)
Continue
echo "$i";
$i + +; Note that the i++ here will not be executed, resulting in a dead loop
}