Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.