PHP Theory
Switch Statement
The switch statement works like if-else-if statement and it is used to executes one statement from multiple conditions.
- The switch declaration is evaluated once.
- The value of the expression is compared to the value of each case.
- If there is a match the value of case, then the block of code to be executed.
Break statement:
Break statement is used to control the flow of the execution, the expression is satisfied the execution moves out the switch case block.
Syntax |
---|
switch($ch) { Case 'a': //code to be executed if $ch=a; break; Case 'b;: //code to be executed if $ch=b; break; Case 'n': //code to be executed if $ch=n; break; default: //code to be executed if ch doesn't match any case; break; } |