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 trialjon willey
845 Pointshow do I loop $names in for each loop challenge task 2 of 2? can't see to get it
how do I loop $names in for each loop challenge task 2 of 2? can't see to get it
<?php
$names = array('Mike', 'Chris', 'Jane', 'Bob');
?>
<?php
foreach($names as $name){
?>
<?php echo $name?>
<?php
}
?>
2 Answers
Gianmarco Mazzoran
22,076 PointsHi,
you can write your foreach loop inside of one php tag.
And in order to pass the challenge, seems like you forgot to put a semi-colon! Can you guess where?
Luke Pettway
16,593 PointsYou are missing a semi colon on this line:
<?php echo $name?>
//Shoud be
<?php echo $name;?>
You can also omit most of your php tags since you aren't mixing any other content like HTML in your code yet
<?php
$names = array('Mike', 'Chris', 'Jane', 'Bob');
foreach($names as $name){
echo $name;
}
?>
Keeping your code cleaner like the code above can help aid in catching errors.