PHP has three major process controls: sequence control, branch control, and loop control.
1. Sequential control: The program is executed step by step from top to next in order.
2. Branch control: Selective execution of the program. It is also divided into single branch, multiple branches, and multiple branches.
a. Single branch: basic grammatical structure:
if(conditional expression){
Statement;
//....;
} Tip: No matter how complex the conditional expression is, it will ultimately be true or false;
eg:
a=11;
if(a>10){
echo "a>10";
}
b. Multi-branch: basic syntax:
if(conditional expression){
Statement;
//....;
}else{
Statement;
//....;
}
c, multiple branches: basic syntax:
if(conditional expression){
Statement; n statements;
}else if(conditional expression){
statement;n statements;
}elseif(conditional expression){
statement;n statements;
}eles{
statement;n statements;
} Tips: 1. Else if can have one or more. 2. The last else does not need to be
d, switch branch statement
switch(expression){
case constant 1:
Statement; n statements;
break;
Case constant 2:
Statement; n statements;
break;
case constant 3:
Statement; n statements;
break;
default:
statement; n statements;
break;
} Note:
Key points: The program is first configured in case order. If none is matched, the content of the default statement will be executed until break is encountered, and the switch will exit;
Comparison of if and switch branch :
if is a judgment on a certain range, and switch is a judgment on a point, so we can select them like this: