Let's talk about the format of the switch () statement.
switch (expression) {
Case Match 1:
When matching 1 and expression matches the code executed successfully;
Break
Case Match 2:
When matching 2 and expression matches the code executed successfully;
Break
Default
If the case statement does not have the code executed with the expression success;
}
It is important to understand how switch is executed. The switch statement executes one line after the other (in fact, a statement). No code was executed at the beginning. Only when the value in one case statement matches the value of the switch expression does PHP begin executing the statement until the end of the switch's program segment or the first break statement is encountered. If you do not write a break at the end of the statement segment of the case, PHP continues to execute the statement segment in the next case.
Example:
Copy CodeThe code is as follows:
Switch ($i) {
Case 1:
The value of echo "$i is 1";
Break
Case 2:
The value of echo "$i is 2";
Break
Case 3:
The value of echo "$i is 3";
Break
Default
echo "$i value is not 1, 2, 3";
}
?>
The statement in one case can also be empty, so that only the control is transferred to the statement in the next scenario, knowing that the statement block of the next case is not empty, thus implementing multiple value matching consent blocks:
When the value of $i is 1 or 2 or 3 o'clock, the same statement is output:
Copy CodeThe code is as follows:
Switch ($i) {
Case 1:
Case 2:
Case 3:
The value of echo "$i is $i 1 or 2 or 3";
Break
}
?>
http://www.bkjia.com/PHPjc/736819.html www.bkjia.com true http://www.bkjia.com/PHPjc/736819.html techarticle first, the format of the switch () statement, switch (expression) {case Match 1: When matching 1 and expression matches the code executed successfully; break, case match 2: when match 2 and expression match successfully executed ...