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

Evans B. Ofori
PLUS
Evans B. Ofori
Courses Plus Student 13,720 Points

php array code challenge.

I do not understand the question below (changing it instead to display the value for the array element under consideration inside the foreach loop.)

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. <?php

$letters = array("D", "G", "L"); echo "My favorite "; echo count($letters); echo " letters are these: "; foreach($letters as $letter){ echo $letter. "\n"; echo "AB"; //echo $letters[0]. $letters[1]. $letters[2]; } echo ".";

?>

4 Answers

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

I think you completed half of this step already! :-) Good job anticipating what you would do next, but I can see how it's causing a little confusion. At the beginning of this step, the code should display "ABABAB":

<?php

$letters = array("D", "G", "L");
echo "My favorite ";
echo count($letters);
echo " letters are these: ";
foreach($letters as $letter){
    echo "AB";
}
echo ".";

?>

There's a line of code in there that displays a static piece of text:

echo "AB";

You need to change that to display the value from the array, like this:

echo $letter;

You have already added that line, but you still have the other line that displays ABABAB. Remove that line, and you should be good to go.

Does that make sense?

Evans B. Ofori
PLUS
Evans B. Ofori
Courses Plus Student 13,720 Points

Yes! Now it passed. Thanks a lot. I added concatenation and line break to my previous question (Q 5) code, maybe because of that it was not passing. Again, thanks for your fast response.

Will Vincent
Will Vincent
2,594 Points

i cant get it to work, this is my code

<?php

$letters = array("D", "G", "L"); echo "My favorite "; echo count($letters); echo " letters are these: "; foreach($letters as $letter){ echo "AB"; } echo ".";

?>