What is wrong with my PHP code?

  • Thread starter Thread starter Tony Y
  • Start date Start date
T

Tony Y

Guest
Hello, I am a newbie to PHP, I got a problem.

$birthday = array(
'tony' => '19861217',
'bob' => '19861207',
'peter' => '19861220')

foreach ($birthday as $name => $date):
each "$name\'s birthday is $date";
endforeach;

Parse error: syntax error, unexpected T_FOREACH in /home/darkt7/public_html...
 
Apparently, it doesn't like the $date in foreach. See php.net

<?php
$birthday = array(
'tony' => '19861217',
'bob' => '19861207',
'peter' => '19861220');

foreach ($birthday as &$name);

echo $name."'s birthday is $date";

You also had a colon not a semicolon.

?>



Good Luck!
 
Back
Top