php switch
snippet in php

php switch

user7389

$age=20;
switch ($age) {
	case 19:
        echo "Age is 18";
        break;
    case 20:
        echo "Age is 20";
        break;
    case 21:
        echo "Age is 21";
        break;
}

php switich

user5449

switch (n) {
    case label1:
        code to be executed if n=label1;
        break;
    case label2:
        code to be executed if n=label2;
        break;
    case label3:
        code to be executed if n=label3;
        break;
    ...
    default:
        code to be executed if n is different from all labels;
} 

php switch

user6494


 <?php

 $favcolor = "red";


 switch ($favcolor)
 {

   case "red":

      echo "Your favorite color is red!";

      break;

  
 case "blue":

      echo "Your favorite color is blue!";

      break;

  
 case "green":

     echo "Your favorite color is green!";

    
 break;

  
 default:

      echo "Your favorite color is neither red, blue, nor green!";

 }

 ?>
 

dualcase php switch

user4041

case 'car':
case 'ferrari':
    print("car or ferrari");
    break;