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 Simple PHP Application Listing Inventory Items Introducing Arrays

STAGE 4 CHALLENGE TASK 4 OF 7

The second echo statement displays the number of letters, but right now it always shows 2. Change that second echo statement to display the number of elements in the array.

letters.php
<?php



echo "My favorite ";

echo " letters are these: ";
$letters = array ("D", "G", "L");
 echo $letters [D]. "\n" . $letters [G] . "\n" . $letters [L]; 
echo "AB";
echo ".";

?>

1 Answer

Chase Marchione
Chase Marchione
155,055 Points

Hi there,

It seems that the challenge wants us to echo out "My favorite 3 letters are these: AB." You'll get to fix the logic of that sentence later on, but for now, what you want to do with this step is echo out the count of the letters array (in other words, how many values are in the letters array.)

<?php

$letters = array("D","G","L");

echo "My favorite ";
echo count($letters);
echo " letters are these: ";
echo "AB";
echo ".";

?>

Hope this helps.