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 trialAlex Watts
8,396 PointsPHP Function Arguments.
Hello, why would I need to pass an argument when calling the function? (see below):
function get_name($name) {
echo "Hello, $name";
}
get_name("Alex");
Thanks!
2 Answers
Mark Hill
9,047 PointsBecause in the function definition there is a required argument. You can make it optional by doing
function get_name($name = "default") {
echo "Hello, $name";
}
Alex Watts
8,396 PointsThanks all for your help!
Cody Te Awa
8,820 PointsCody Te Awa
8,820 PointsHi Alex, Is there any way you could be more specific about your the question? From the looks of things, the reason an argument is necessary so that the echo statement can echo the supplied argument. Is there something else that is confusing you? :)