swithc case code example
Example 1: php switch
$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;
}
Example 2: switch js
switch(expression) {
case x:
break;
case y:
break;
default:
}
Example 3: switch case in
function whatToDrink(time){
var drink ;
switch (time) {
case "morning":
drink = "Tea";
break;
case "evening":
drink = "Shake";
break;
default:
drink="Water";
}
return drink;
}
console.log(whatToDrink("morning"))
console.log(whatToDrink("evening"))
console.log(whatToDrink("night"))
console.log(whatToDrink("daytime"))
Example 4: dualcase php switch
case 'car':
case 'ferrari':
print("car or ferrari");
break;