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

how to echo the 3 names correctly

not sure what i did wrong

index.php
<?php 
$names = array('Mike', 'Chris', 'Jane', 'Bob');

foreach($names as $name){ 
  echo "$name"};

?>

2 Answers

Sebastian Wilson
Sebastian Wilson
15,710 Points

Hi, in your foreach your are missing a semicolon and you do not need one at the end of your } .

<?php

$names = array('Mike', 'Chris', 'Jane', 'Bob');

foreach($names as $name) { echo "$name "; }

?>

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

The problem is the misplacing ; in the code.

<?php 
$names = array('Mike', 'Chris', 'Jane', 'Bob');

foreach($names as $name) {
  echo $name;
}
?>