PHP Switch Statement
The switch statement is used to execute different actions based on multiple different conditions.
PHP Switch Statement
If you wantto selectively execute one of several code blocks, please use the switch statement.
Syntax
Parameter Description:
expressionis the expression to be compared.case value:is the possible value; ifexpressionthe value of equals a certaincasevalue, the corresponding code block is executed.break;is used to terminateswitchstatements, to prevent continued execution into the nextcase.default:is optional, used to specify the code block executed when no matchingcaseis found.
**How it works:** First, a simple expression n(usually a variable) is evaluated once. The value of the expression is compared with the value of each case in the structure. If a match exists, the code associated with that case is executed. After the code is executed, use break to prevent the code from jumping into the next case and continuing execution.default statement is used to execute when there is no match (i.e., no case is true).
Example
Run Example »