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 trialJohn van Vugt
4,486 Pointscode 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?
<?php
$names = array('Mike', 'Chris', 'Jane', 'Bob');
foreach ($names as $val) { ?> <ul><?php
echo "<li>$val </li>";
?></ul> <?php }
?>
2 Answers
William Li
Courses Plus Student 26,868 PointsHi, John:
Ummm.. looks like there're 2 problems here.
- the code included some unnecessary tag elements in line 3 & 5, these are going to cause problem with the grader.
- it echos the wrong value.
<?php
$names = array('Mike', 'Chris', 'Jane', 'Bob');
foreach ($names as $val)
echo $val;
?>
John van Vugt
4,486 Pointsokay thank you so much for explaining. I will keep my code clean next time in a test.