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 Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Introducing Arrays

PHP help ?

Martin Guzman3,019 Build a Basic PHP Website Challenge Task 4 of 4

The original code was hard-coded to echo the letters "AC" instead of the contents of the $letters array. Replace the fourth echo statement with a foreach loop that prints each letter in the array. Bummer! We don't see 'ACME' in the output. Preview Get Help Reset Code Recheck work index.php ;

; 1 <?php 2 $letters = array ( "A", "C","M", "E"); 3 ​ 4 ​ 5 echo "Today's challenge is brought to you by the "; 6 echo count ($letters); 7 echo " letters: "; 8 foreach ($letters as $item){ 9

10 echo "<li>" . $item . "</li>"; 11

12 }; 13 echo "."; 14 ​ 15 ?> Career Resources

Get tips and resources on how to prepare for and find a new job in the industry. Treehouse for Mobile

Learn anytime and anywhere with Treehouse for iPad or Android. Download for free today. Student Perks

A collection of special discounts and exclusive offers available for Treehouse students. Treehouse BlogAbout TreehousePrivacy PolicyTerms & ConditionsΒ©2016 Treehouse Island, Inc.

index.php
<?php
$letters = array ( "A", "C","M", "E");


echo "Today's challenge is brought to you by the ";
echo count ($letters);
echo " letters: ";
foreach ($letters as $item){

  echo "<li>" . $item . "</li>";

};
echo ".";

?>

1 Answer

Geovanie Alvarez
Geovanie Alvarez
21,500 Points

Try this

<?php
$letters = array("A", "C", "M", "E");

echo "Today's challenge is brought to you by the ";
echo count($letters);
echo " letters: ";
foreach($letters as $item){
  echo $item;
}
echo ".";
?>