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

Abe Layee
Abe Layee
8,378 Points

PHP foreach() loop.

I am currently practicing my PHP skills and I came across this bug. I have no clue what I am doing wrong with foreach(){} loop. The first value in foreach() loop is the name of the variable right? The second statement is the counter right?

<?php 
   $friends = array('Joe','Solo','Chris','David','John');
   foreach($friends as counter) {
     echo $counter;
   }
   ?>

I am getting this error each time I run this on my local server. Parse error: syntax error, unexpected ')', expecting '(' in C:\xampp\htdocs\PHP\index.php on line 11. Thanks in advance

2 Answers

Alexander Budkin
Alexander Budkin
2,231 Points

Hello.. You forget '$' before counter var

like this: foreach($friends as $counter) { echo $counter; }

Abe Layee
Abe Layee
8,378 Points

Lol, thank you didn't see it:D