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 PointsHelp
Why isn't this code working?
<?php
$letters = array("D","G","L","R");
echo "My favorite ";
echo "3";
echo " letters are these: ";
foreach($letters as $letter){
echo $letter;
}
echo ".";
?>
2 Answers
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 PointsI forgot to echo "4" instead of "3".
Oops:-)
Henrik Hansen
23,176 PointsYou could automize the number of letters this way:
<?php
$letters = array("D","G","L","R");
$stringToPrint = "My favorite " + count($letters) + " are these: \n";
foreach($letters as $letter){
$stringToPrint += $letter + "\n";
}
echo $stringToPrint;
?>
Juliette Tworsey
Front End Web Development Techdegree Graduate 32,425 PointsThar's an interesting approach. Thanks Henrik!
Henrik Hansen
23,176 PointsHenrik Hansen
23,176 PointsWhat is the error?