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 trialSimingaye Dube
2,587 Pointsuse the foreach to loop names Mike, Chris, Jane and Bob in the array $names
use the foreach to loop names Mike, Chris, Jane and Bob in the array $names
<?php
$names = array('Mike', 'Chris', 'Jane', 'Bob');
foreach (Mike; Chris; Jane; Bob;) as $names{
echo $names;
}
?>
2 Answers
Mikkel Rasmussen
31,772 Points<?php
$names = array('Mike', 'Chris', 'Jane', 'Bob');
foreach ($names as $name) {
echo $name;
}
?>
Alexander Davison
65,469 PointsGreat job There are some weird things going on though:
- You shouldn't say the contents of the array in the (), instead, just say the name of the array (in this case, it is $names)
- Put the as $names part into the ().
- Name second $names (the one after the as) name.
With all of that, you should end up like this (yeah you can just copy and paste this stuff):
<?php
$names = array('Mike', 'Chris', 'Jane', 'Bob');
foreach ($names as $name) {
echo $name;
}
?>
Hope that helps!