PHP switch Statement


The switch statement in PHP is used to perform one of several different actions based on one of several different conditions. The switch statement is used to avoid long blocks of if..elseif..else code.

switch ( expression ) {
  case label1:
    code to be executed if expression = label1;
    break;
  case label2:
    code to be executed if expression = label2;
    break;
  default:
    code to be executed if expression is different from both label1 and label2;
}
The function strtoupper makes a string uppercase, which could be used in case-insensitive matching.

 <html><body>
 <?php
   switch ( strtoupper( $day ) ) {
     case 'FRIDAY':
       echo "Weekend is coming :)";
       break;
     case 'SATURDAY':
       echo "Nice weekend :)";
       break;
     case 'SUNDAY':
       echo "Weekend is ending :|";
       break;
     default:
       echo "Another workday :(";
   }
 ?>
 </body></html>
$day =