This is my php code:
switch ($i) {
case 0:
echo '$i is 0.';
break;
case 1:
case 2:
case 3:
case 4:
case 5:
echo '$i is somewhere between 1 and 5.';
break;
case 6:
case 7:
echo '$i is either 6 or 7.';
default:
echo "I don't know how much \$i is.";
}
?>
Now, how can I make the code using alternative syntax rather than curly-brace syntax?
In this case i dont even feel there is a requirement of using Switch, better go with if or if else statement.
if($i==0){
echo "value is 0";
} else if($i>0 && $i<6){
echo "value is between 1 and 5";
}else if($i>5 && $i<8){
echo "value is 6 or 7";
}else{
echo "unknown value";
}
The actual answer to your question if you want to use alternative syntax with this example is:
switch ($i):
case 0:
echo '$i is 0.';
break;
case 1:
case 2:
case 3:
case 4:
case 5:
echo '$i is somewhere between 1 and 5.';
break;
case 6:
case 7:
echo '$i is either 6 or 7.';
default:
echo "I don't know how much \$i is.";
endswitch;
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With