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

Brian Platt
Brian Platt
5,009 Points

Echo count not passing

<?php echo "My favorite "; echo count($letters); echo " letters are these: "; echo "AB"; echo "."; $letters = array("D","G","L");

?>

My code isn't passing, it still says that I need to echo 3 letters to the screen, am I doing something wrong here?

letters.php
<?php



echo "My favorite ";
echo count($letters);
echo " letters are these: ";
echo "AB";
echo ".";
$letters= array("D","G","L");

?>

2 Answers

Its not passing because of the cascading nature of where you put the $letters array. you are echoing it before the program reads it. put your array before echo "My favorites" and you should be good to go.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

It looks to me like you're trying to use the count function on your array but this will only display 3 which is the number of values in your array.

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

echo "My favorite ";
echo " letters are these: ";

echo $letters;

?>

Try assigning your array to a variable at the top of your code and then echoing out the variable. :-)