decypher Posted July 19, 2007 Share Posted July 19, 2007 <?php print verse(1); print chorus(); print verse(2); print chorus(); print verse(3); print chorus(); print verse(4); print chorus(); function verse($stanza){ switch ($stanza){ case1: $place = "thumb"; break; case2: $place = "shoe"; break; case3: $place = "knee"; break; case4: $place = "door"; break; defeault: $place = "I don't know where"; break; } // end switch $output = <<<HERE This old man, he played $stanza<br> he played knick-knack on my $place<br><br> HERE; return $output; } // end verse Error: Parse error: syntax error, unexpected T_STRING, expecting T_CASE or T_DEFAULT or '}' in C:\Program Files\Abyss Web Server\htdocs\paramoldman.php on line 22 any ideas? Link to comment https://forums.phpfreaks.com/topic/60745-solved-function-switch/ Share on other sites More sharing options...
ToonMariner Posted July 19, 2007 Share Posted July 19, 2007 <?php function verse($stanza){ switch ($stanza) { case1: $place = "thumb"; break; case2: $place = "shoe"; break; case3: $place = "knee"; break; case4: $place = "door"; break; defeault: $place = "I don't know where"; } } // end switch ?> Link to comment https://forums.phpfreaks.com/topic/60745-solved-function-switch/#findComment-302184 Share on other sites More sharing options...
chigley Posted July 19, 2007 Share Posted July 19, 2007 Was the error not in the typo of default? Link to comment https://forums.phpfreaks.com/topic/60745-solved-function-switch/#findComment-302197 Share on other sites More sharing options...
decypher Posted July 19, 2007 Author Share Posted July 19, 2007 yeh it was default: and the 'cases' had to have a space between the numbers :] Link to comment https://forums.phpfreaks.com/topic/60745-solved-function-switch/#findComment-302261 Share on other sites More sharing options...
ToonMariner Posted July 19, 2007 Share Posted July 19, 2007 the error was an omission of the closing brace for the switch statement. (I have only just noticed the typos) it shoudl all look like this <?php function verse($stanza){ switch ($stanza) { case 1: $place = "thumb"; break; case 2: $place = "shoe"; break; case 3: $place = "knee"; break; case 4: $place = "door"; break; default: $place = "I don't know where"; } } // end switch ?> Link to comment https://forums.phpfreaks.com/topic/60745-solved-function-switch/#findComment-302306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.