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 trialBrecht Philips
8,863 PointsWon't accept my php code while it works..
i think my code is correct but it keeps saying using te wrong array
<?php
$names = array('Mike', 'Chris', 'Jane', 'Bob');
foreach ( $names as $name ) {
echo $name." ";
}
?>
Jason Anders
Treehouse Moderator 145,860 PointsThe variable name would not have mattered. In fact, PHP convention is to name the variable in a foreach
loop as the singular of the array name, so you were correct in the naming convention. The error was with the added coded, not the name of the variable.
<?php
$names = array('Mike', 'Chris', 'Jane', 'Bob');
foreach ($names as $name) {
echo $name;
}
?>
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Brecht,
Your code is correct, but you added some code that was not asked for by the challenge. In the echo
statement, the challenge just wants you to "echo out each name." It didn't ask for any concatenation, so you just need to delete the ." " that you added.
Challenges are very picky and specific.
Keep Coding!
Gianmarco Mazzoran
22,076 PointsHi,
your code is ok except one thing, you don't need this code: ." ";
<?php
$names = array('Mike', 'Chris', 'Jane', 'Bob');
foreach ( $names as $name ) {
echo $name;
}
?>
$name can be replaced with anything you want.
Brecht Philips
8,863 PointsBrecht Philips
8,863 PointsGot it to work i changed my $name variable to $something and it accepted it. i think is didn't got the difference between $names and $name