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 trialJuliette Tworsey
Front End Web Development Techdegree Graduate 32,425 PointsWhy isn't this working?
Hi,
I am following the instructions. Am I missing something?
Thanks-
<?php
$letters = array("D", "G", "L");
echo "My favorite ";
echo "3";
foreach {
echo " letters are these: ";
echo "AB";
}
echo ".";
?>
2 Answers
Fernando Claussen
9,324 PointsAs far as I remember, this exercise asks you to replace the number 3 for the array count and the letters AB with the letter that are inside the array.
The answer would be, replace the 3 for:
echo count($letters)
And replace AB for:
foreach($letters as $letter){
echo $letter;
}
Cory Allen
730 Points<?php
$letters = array("D", "G", "L");
echo "My favorite ";
echo "3";
foreach {
echo " letters are these: ";
echo "AB";
}
echo ".";
?>
Is not correct!
Your loop is not getting any information from the array, therefore it doesn't really know what to do! :P
<?PHP
$letters = array("a", "B", "c");
foreach($letters as $letter) {
echo $letter . ' <br />';
}
?>