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

Oğulcan Girginc
Oğulcan Girginc
24,848 Points

Stuck in the PHP Development Code Challenge: Introducing Arrays

Hi, this is the challenge:

The fourth echo statement, the one inside the foreach loop, should display my favorite letters from the array INSTEAD of AB. Remove the static piece of text from that fourth echo statement, changing it instead to display the value for the array element under consideration inside the foreach loop.

However, I couldn't understand what does it ask for in the second sentence. It is keep saying: Bummer! You seem to have too many letters. You should only be displaying one letter inside your foreach loop.

Can someone help please?

Thanks! :)

letters.php
<?php

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

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

echo "A B";
echo ".";

?>

3 Answers

The output for your code is basically correct, I imagine the problem stems from the use of the <pre> tag. Occasionally formatting issues will cause "Bummers" in treehouse. I cleaned up your code above and got it to pass successfully.

A great resource to test and debug code for these challenges is: http://sandbox.onlinephpfunctions.com/ This sandbox will allow you to see if your code functions correctly, and if not you can find the line number and error type.

<?php

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

echo "My favorite ";
echo count($letters);
echo " letters are these: ";
foreach($letters as $letter) {
  echo $letter;
}
echo ".";

?>

Hope this helps!

Clayton Perszyk
MOD
Clayton Perszyk
Treehouse Moderator 48,850 Points

Try removing echo "A B";. If that doesn't work you might need to remove the new-line characters.

Oğulcan Girginc
Oğulcan Girginc
24,848 Points

I have ended up like this:

<?php

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

?>
<pre><?php
echo "My favorite ";
echo count($letters);
echo " letters are these:";
foreach($letters as $letter) {
  echo $letter;
}

echo ".";

?>            

But it keeps saying: "Bummer! You seem to have too many letters. You should only be displaying one letter inside your foreach loop."

Anymore ideas?