PHP Switch statement
the switch statement is execute multiple condition and select user defined condition is display.
PHP switch statement is used to execute one statement from multiple conditions. It works like PHP if-else-if statement.
Syntax
- switch(expression){
- case value1:
-
- break;
- case value2:
-
- break;
- ......
- default:
- code to be executed if all cases are not matched;
- }
PHP Switch Flowchart
PHP Switch Example
- <?php
- $num=20;
- switch($num){
- case 10:
- echo("number is equals to 10");
- break;
- case 20:
- echo("number is equal to 20");
- break;
- case 30:
- echo("number is equal to 30");
- break;
- default:
- echo("number is not equal to 10, 20 or 30");
- }
- ?>
Output:
number is equal to 20