Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Basic PHP Website Listing and Sorting Inventory Items Introducing Arrays

Help me find the error in my code

It worked until I tried to echo all the items in my $letters array with a foreach statement. I have probely made a error on line 8 or 9. plz help

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 $value){echo "$value"
                             } ;
echo ".";

?>

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 90,704 Points

What's happening is you're trying to log your variable output in line 9 but because you're echoing out as a string, PHP treats it as such and literally outputs $value to the console/screen.

So you're almost there. But try modifying your code so you're referencing the variable name by removing the quotes.

I've also modified the indentation a little bit.

<?php

    foreach ($letters as $value) {
        echo $value;
    };

    echo ".";

Let us know if that helps! :-)

Thanks