How to do using "alternative syntax" and not "curly bracket syntax" in php? (Using Syntactic Sugar for Endswitch)

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 code using alternative syntax rather than curly bracket syntax ?

+7
syntax php
source share
2 answers

In this case, I donโ€™t even feel that there is a requirement to use Switch, it is better to go with if or if else.

 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"; } 
+2
source share

The actual answer to your question is if you want to use alternative syntax with this example:

 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; ?> 
+2
source share

All Articles