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 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 91,252 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