switch allows selection of multiple possible results of a scalar (expression).
Syntax:
switch (expr) { case result1: statement1 break; case result2: statement2 break; …… default: statement }
The system calculates the value of expr and selects the corresponding execution statement below based on the calculation results (result1, result2, etc.). If all case results do not match, the statement in default will be executed.
Example:
<?php switch ($x) { case 0: echo "x 等于 0"; break; case 1: echo "x 等于 1"; break; case 2: echo "x 等于 2"; break; default: echo "x 既不等于1和2,也不等于0"; } ?>
Tips
•There can be multiple case conditional judgments
•The result after the case is not limited to numbers, but can also be characters or other types supported by PHP
•default is not required
The above simple example of PHP process control switch is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support Bangkejia.