Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKeith Miller
2,310 PointsMy code is only returning one name, Hampton. What am I missing?
Here is my code:
<?php
$names = array( 'Mike' => 'Frog', 'Chris' => 'Teacher', 'Hampton' => 'Teacher' );
foreach (array_keys($names) as $name);{ echo "Hello, $name</br>"; }
//array_walk()
?>
2 Answers
Casey Phillips
5,546 PointsIt looks like you have an error after your foreach line. There is an unneeded semicolon after your end parenthesis. should be:
foreach (array_keys($names) as $name){ echo "Hello, $name</br>"; }
not sure why it only showed the last name though, but removing the semicolon fixes it.
jamesjones21
9,260 PointsAs stated above there was a semi colon, but it is weird how it ran the array without showing an error.
$names = array( 'Mike' => 'Frog', 'Chris' => 'Teacher', 'Hampton' => 'Teacher' );
foreach (array_keys($names) as $name)
{ echo "Hello, $name</br>";
}
Keith Miller
2,310 PointsKeith Miller
2,310 PointsThanks! I had to have scanned that at least 5 times and didn't see that.