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

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.