See if you can spot the error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
soma56
Forum Newbie
Posts: 11
Joined: Fri Jul 10, 2009 12:12 pm

See if you can spot the error

Post by soma56 »

This one works:

Code: Select all

<h1>This Old Man with Arrays</h1>
<?php 
$place = array(
  "",
  "on my thumb",
  "on my shoe",
  "on my knee",
  "on a door");
  
//print out song
for ($verse = 1; $verse <= 4; $verse++){
print <<<HERE
 <p>
 This old man, He played $verse <br />
 He played knick-knack $place[$verse] <br />
 ...with a knick, knack, paddy-whack <br />
 give a dog a bone <br />
 This old man came rolling home 
 </p>
HERE;
  } // end for loop

?>
This one doesn't:

Code: Select all

<h1>This Old Man with Arrays</h1>
<?php 
$place = array(
  "", 
  "on my thumb",
  "on my shoe",
  "on my knee",
  "on a door");

//print out song
for ($verse = 1; $verse <= 4; $verse++){
print <<<HERE
 <p>
 This old man, He played $verse <br />
 He played knick-knack $place[$verse] <br />
 ...with a knick, knack, paddy-whack <br />
 give a dog a bone <br />
 This old man came rolling home 
 </p>
HERE; 
  } // end for loop
  
?>
what's different?
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: See if you can spot the error

Post by mikosiko »

in the second one remove the space that you have after

Code: Select all

HERE; 
Post Reply