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

Danang Indroharto
Danang Indroharto
3,472 Points

Need help! I'm stuck on challenge code on task 6 of 7 in stage 4 of Build a Simple PHP application

Here is the instruction:

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.

Somebody please help me, I'm stuk in here

letters.php
<?php

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

echo "My favorite ";
echo count($letters);

foreach ($letters as $letter){
  echo " letters are";
  echo $letter;
}
echo ".";

?>
Zack Klinger
Zack Klinger
17,622 Points

I'm pretty sure that would output "My favorite letters areDletters areGletters areL.

2 Answers

Jack McDowell
Jack McDowell
37,797 Points

Hello, I just went back and tested the Code Challenge again and came up with this passing answer. It looks like the problem is that you are missing "are these: ":

<?php

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


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

?>
Kevin Fitzhenry
Kevin Fitzhenry
30,096 Points

Danang Indroharto I think you simply need to add "these:" to the first echo statement inside the foreach loop.

echo " letters are these:"

As the final output should read: My favorite 3 letters are these: DGL.

Hope that helps.