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!

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 trial

PHP PHP Functions PHP Internal Functions PHP Array Functions

My code is only returning one name, Hampton. What am I missing?

Here is my code:


$names = array( 'Mike' => 'Frog', 'Chris' => 'Teacher', 'Hampton' => 'Teacher' );

foreach (array_keys($names) as $name);{ echo "Hello, $name</br>"; }



2 Answers

It 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.

Thanks! I had to have scanned that at least 5 times and didn't see that.

9,260 Points

As 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>";