The best PHP Switch Statement Tutorial In 2024, In this tutorial you can learn PHP Switch Statement,Examples,
switch statement is used to perform different actions based on a number of different conditions.
If you want to selectively execute one of several blocks of code, use the switch statement.
switch (n) { case label1: 如果 n=label1,此处代码将执行; break; case label2: 如果 n=label2,此处代码将执行; break; default: 如果 n 既不等于 label1 也不等于 label2,此处代码将执行; }
How it works: First, a simple expressionn (usuallyvariable) once calculated. The value and structure of the expression in each case were compared. If there is a match, the case associated code is executed. After the code is executed, using thebreak to prevent the code jump to the next case to continue execution.Executive default statement is used to match does not exist (that is, no case is true) time.