aszxcv Posted August 9, 2008 Share Posted August 9, 2008 The Switch Statement i am having difficulty understanding this concept when i practice i like to change examples so i can learn by messing with codebut i am keep error with my modificationso can someone modified the example below so i can see java script:bbc_pop() <html><body><?phpswitch ($x){case 1: echo "Number 1"; break;case 2: echo "Number 2"; break;case 3: echo "Number 3"; break;default: echo "No number between 1 and 3";}?></body></html> Link to comment Share on other sites More sharing options...
jeffman Posted August 9, 2008 Share Posted August 9, 2008 Well, if that's the EXACT code in your script, you haven't assigned $x a value, so you can't really test it. Otherwise, it seems fine. What error are you getting? Link to comment Share on other sites More sharing options...
aszxcv Posted August 9, 2008 Author Share Posted August 9, 2008 thats w3school tutorial script it works togives default statementthe problem i have is i dont understand where to give $x value or how to modify it so i can get case 1 statement of "Number 1" Link to comment Share on other sites More sharing options...
Ingolme Posted August 9, 2008 Share Posted August 9, 2008 Just assign 1 to $x: <?php$x = 1;switch ($x){case 1: echo "Number 1"; break;case 2: echo "Number 2"; break;case 3: echo "Number 3"; break;default: echo "No number between 1 and 3";}?> the switch() statement is like a series of ifs. Here's an equivalent to your switch statement: if ($x == 1) { echo "Number 1";} else if($x == 2) { echo "Number 2";} else if($x == 3) { echo "Number 3";} else { echo "No number between 1 and 3";} Link to comment Share on other sites More sharing options...
aszxcv Posted August 9, 2008 Author Share Posted August 9, 2008 thanks alot i see now Link to comment Share on other sites More sharing options...
aszxcv Posted August 10, 2008 Author Share Posted August 10, 2008 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><?php$date1 = date(d);switch ($date1){ case 10: echo "today tenth"; break; case 14: echo "not"; break; case 7: echo "today 17"; break; default: echo:"not 10";} ?> i have this code but i am getting error Link to comment Share on other sites More sharing options...
Ingolme Posted August 10, 2008 Share Posted August 10, 2008 Here's the mistake:echo:"not 10"; Link to comment Share on other sites More sharing options...
aszxcv Posted August 10, 2008 Author Share Posted August 10, 2008 lol thanks :it was a silly error took me forever to see it Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.