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 trial

PHP Build a Simple PHP Application Listing Inventory Items Introducing Arrays

Peter Shackelford
Peter Shackelford
1,409 Points

I am getting "you should only be displaying one letter in your foreach loop".

I am getting this message "You seem to have too many letters. You should only be displaying one letter inside your foreach loop."

When I preview I see the each of the letters echoed out once as expected. Not sure what is wrong here.

$letters = array("D", "G", "L");

echo "My favorite ";
echo count($letters);
echo " letters are these:\n";
foreach ($letters as $letter){
echo $letter . "\n";
}
echo ".";
?>```

2 Answers

Hello,

I redid this code challenge again and the only thing I see different between yours and mine that passed was the addition of the "\n". It is not asking you to display the letters on different lines, just to display the letters in the array. The error may be misleading, but get rid of the newline character and you should pass.

Cheers!

Peter Shackelford
Peter Shackelford
1,409 Points

Thanks Shawn. I'll go give it a try. Just getting back into things after summer started kicking in.