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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Gremyko Coleman](https://secure.gravatar.com/avatar/36c42b3db08066472ba1d836e5a3fb23?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Gremyko Coleman
9,756 PointsConfused about this example
I am confused, as the argument the array is named, $user_array, why when the array is declared inside the function the array is called $name instead of being called $user_array like how it was in the argument at the beginning?
<?php function welcome_dialog($user_array) { if(is_array($user_array)) { foreach($user_array as $name) { echo "Hello, $name, how are you?</br>"; } } else { echo 'Hello friends</br>'; } }
$name = array(
'Kcin',
'Sharon',
'Brother',
'Sister'
);
welcome_dialog($name);
?>
2 Answers
![David Olson](https://uploads.teamtreehouse.com/production/profile-photos/6262592/micro_Screenshot_from_2017-08-10_18-45-55.jpg)
David Olson
8,690 PointsThe $name array is actually set outside of your function. It is then passed into the function by adding the line welcome_dialog($name);
The $user_array argument is just a placeholder. By passing in $name it takes the place in all locations within the function where $user_array is used.
![Rafael silva](https://uploads.teamtreehouse.com/production/profile-photos/6528802/micro_feesrzs.jpg)
Rafael silva
23,877 PointsI will to show for you some example, let's go , firts :
//create a function
function hello($arr){
if(is_array($arr)){ //using a if statement to compare if is array the $arr
foreach($arr as $name){ //for each element $arr as $name, now $name is $arr ..
echo "Hello $name , how it's going!<br >\n";
}
}else{
echo 'Hello friends!';
}
}
$names = array( //we have create an array 'Rafael', 'Mike', 'macedo' );
hello($names); //$names is an argument inside of hello , $names is equal to $arr and $arr is equal to $name all names are inside of an array now belong to $name , I hope help you ...