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 PHP Basics (Retired) PHP Conditionals & Loops PHP Loops Challenge

John van Vugt
John van Vugt
4,486 Points

code is working but the program is saying I am not using the right code but I do use the right code

<?php $names = array('Mike', 'Chris', 'Jane', 'Bob'); foreach ($names as $val) { ?> <ul><?php echo "<li>$val </li>"; ?></ul> <?php } ?>

Program is saying Im not using the variable of the for each loop. But I have a var called $val and use it in the echo statement also the output is showing that it loops correctly but the programm is not passing my code. Why?

index.php
<?php 
$names = array('Mike', 'Chris', 'Jane', 'Bob');
foreach ($names as $val) { ?> <ul><?php
   echo "<li>$val </li>";
?></ul> <?php }
?> 

2 Answers

William Li
PLUS
William Li
Courses Plus Student 26,868 Points

Hi, John:

Ummm.. looks like there're 2 problems here.

  1. the code included some unnecessary tag elements in line 3 & 5, these are going to cause problem with the grader.
  2. it echos the wrong value.
<?php 
$names = array('Mike', 'Chris', 'Jane', 'Bob');
foreach ($names as $val)
  echo $val;
?>
John van Vugt
John van Vugt
4,486 Points

okay thank you so much for explaining. I will keep my code clean next time in a test.