Free download web templates, books and more. Free php projects ,games and apps. GTA mods and more

Breaking

PHP switch statement

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
  1. switch(expression){      
  2. case value1:      
  3.  //code to be executed  
  4.  break;  
  5. case value2:      
  6.  //code to be executed  
  7.  break;  
  8. ......      
  9. default:       
  10.  code to be executed if all cases are not matched;    
  11. }  
PHP Switch Flowchart
flowchart of switch statement in php
PHP Switch Example
  1. <?php    
  2. $num=20;    
  3. switch($num){    
  4. case 10:    
  5. echo("number is equals to 10");    
  6. break;    
  7. case 20:    
  8. echo("number is equal to 20");    
  9. break;    
  10. case 30:    
  11. echo("number is equal to 30");    
  12. break;    
  13. default:    
  14. echo("number is not equal to 10, 20 or 30");    
  15. }   
  16. ?>    
Output:
number is equal to 20