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 Functions Introducing Functions PHP Function Arguments

mohammed abdi abdulahi warsame
mohammed abdi abdulahi warsame
4,926 Points

couldent we just sett $arr as avriabel instead of $names?

in the code it says that=> function hello($arr),, and then when he is echoing he is using $name!!! couldent he just mentioned $arr DIRECTLY!!! Hope that my question is understand thanks alot

1 Answer

Kevin Korte
Kevin Korte
28,148 Points

He he can't, it's the way foreach loops work. Foreach loops take an argument, in this case an array of names in $arr and one by one, loads each individual name into a temporary variable that is only available inside of the foreach loop.

This explains it in more detail: http://php.net/manual/en/control-structures.foreach.php