shad Posted December 22, 2011 Share Posted December 22, 2011 <?php$x=9843switch ($x){case 1: echo "one";break;case 2: echo "two"; break;case 3: echo "three"; break;case 4: echo "four" break;case 5: echo "five"; break;case 6: echo "six"; break;case 7: echo "seven"; break;case 8: echo "eight"; break;default:echo "zero";}?> when I run this program it's displayed in browser asParse error: syntax error, unexpected T_SWITCH in C:\xampp\htdocs\switch.php on line 3 note : the program has to be generated using loops and conversion methodso little bit confusion Link to comment Share on other sites More sharing options...
Don E Posted December 22, 2011 Share Posted December 22, 2011 Try adding a semi colon for $x = 9843; and for case 4: echo "four"; Link to comment Share on other sites More sharing options...
thescientist Posted December 22, 2011 Share Posted December 22, 2011 aside from the syntax error which PHP are telling you about, and Don E pointing them out, you should really look at your code. it should be really obvious that's its not going to work as you expect it. You need to think about these things logically. Understand what you are giving to the switch, and consider the cases you've made for it. Also, Ingolme gave you some advice in your other thread which should point you in the right direction. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 22, 2011 Share Posted December 22, 2011 The switch is testing the value of $x, and checking for 1 through 8. But $x is not 1 through 8, it's over 9000, so the switch will always print "zero" because that's the default if it doesn't match any of the cases. You need to split $x up into individual digits and loop through the digits to print each one. You also left out 9. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.