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

Shilpa Kothari
Shilpa Kothari
4,518 Points

array

Challenge Task 5 of 7

Right now, the text shows the wrong letters; we want it to display my real favorite letters from the array. In the next few tasks, we’ll change that. This task has two steps. (1) Add the start of a foreach loop with an opening curly brace between the third and fourth echo commands. The foreach loop should load each element from the letters array, one at a time, into a working variable named letter. (2) Add the closing curly brace for the foreach loop between the fourth and fifth echo commands. (Leave the letters AB in the fourth echo command for now. At the end of this step, the page should say my favorite letters are ABABAB.) I tried a lot can anyone help. I think I am not able to understand the Question.

<?php
$letters = array();
$letters[] = "D";
$letters[] = "G";
$letters[] = "L";
echo "We have " . count($letters) . " letters.";
?>

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

edited to format code

Shilpa Kothari
Shilpa Kothari
4,518 Points

Hi Ted,

Thanks but my question is it correct or not.

I understand your question, but I have to tell you when I edit the post as a moderator. See my answer below.

1 Answer

Your foreach loop is between the first and second echo statement, not the third and fourth as directed. Plus, no the line below that you have a space between <? and php.

Shilpa Kothari
Shilpa Kothari
4,518 Points

Thanks I think the question are more complicated so try to over do things and the coding is simple.

Just do exactly what it tells you to do. Often error messages tell you what you did wrong. The challenges are not tricky at all.