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 trialTim Ruby
Courses Plus Student 19,038 PointsIntroducing Arrays Task 5 of 7 (SOLVED)
I am having a hard time understanding the directions for task 5 on Introducing Arrays. After watching the tutorial video twice I cannot really grasp what is being asked? Can someone help me out here? I believe this is the supplied code...
<?php
$letters = array("D","G","L");
echo "My favorite ";
echo "3";
echo " letters are these: ";
echo "AB";
echo ".";
?>
5 Answers
Aimee Knight
9,701 PointsHint: Implement the foreach syntax.
foreach ($letters as $value) {
statement;
}
If you're still stuck I'll try to respond tomorrow!
Tim Ruby
Courses Plus Student 19,038 PointsI tried implementing the foreach syntax in where it said to do so, and I was getting an error that said I had too many :'s in the code. Odd because I didn't put a single colon in the code. I GREATLY appreciate this site and what it can offer but it seems like every code challenge gets hung up because of the instructions and I spend 20 minutes trying to see where I went wrong, only to spend another hour in the forums. I will go back in and try again and hopefully figure it out. Thanks for the help Aimee.
Randy Hoyt
Treehouse Guest TeacherHey @Tim, Sorry you are having trouble! In this code challenge, we're trying to create an array of my favorite letters and then display that information from the array to the screen.
- So far your array looks good.
- The code to display the number should use count($letters) so that it always shows the number of elements in the array.
- Instead of showing "AB" the code should use a foreach loop so that it pulls the letters feom the array ("DGL") instead.
Does that help?
Tim Ruby
Courses Plus Student 19,038 PointsThanks for responding @Randy. I took a break from the lesson and worked on something else for a while. I actually havent came back to the Challenge yet, but I will take your info and see if I can find my mistakes. I appreciate the help a ton!
Tim Ruby
Courses Plus Student 19,038 PointsFound my error. I was placing my foreach syntax in the wrong area. I read it as "Between line 3 and 4" but it was actually "Between echo 3 and 4". I finished the rest of the challenge. Thanks for the help everyone!