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 (2018) Listing and Sorting Inventory Items Introducing Arrays

Fotis Pastrakis
Fotis Pastrakis
1,124 Points

Build a Basic PHP challenge not working

In the challenge task 4 of 4, even I complete the code I receive an error where is says: "Oops, It looks like Task 1 is not complete" My code below. If you see any mistake please let me know.

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

?>

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


?>

2 Answers

Thomas Fildes
Thomas Fildes
16,201 Points

Hi Fotis,

The problem is your foreach loop. You are not far away for passing it but there is a slight problem. Please see the code I used to pass this challenge:

<?php

$letters = ["A","C","M","E"];

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

?>

Make sure you assign a value ($letter) that is different to the array ($letters) in your foreach loop and take the last echo statement out of the loop.

Hope this helps! Happy Coding!!!

Fotis Pastrakis
Fotis Pastrakis
1,124 Points

When I am using $letter and $letters isn't it a new variable? So I have to assign it right? Does PHP recognize the difference in foreach loop of a simple 's' that works as a port of an array?