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 (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
22,687 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?