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?