Jump to content

[SOLVED] Function switch


decypher

Recommended Posts

<?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

<?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
?>

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
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.