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
Philip Harper
10,033 PointsWhat is an "Argument"?
Ok, please don't laugh.
I've been learning to tinker with PHP and this word "Argument" keeps coming up and again in the tutorials.
In programming, what does this mean? Seriously, I don't know. I'm ashamed and embarrassed and ashamed, I don't know.
I asked on Stackoverflow but got laughed off stage. It seems it's almost TOO basic, that EVERYONE should know this computer based concept. Even those that don't programme.
Thanks, everyone.
I feel better now I've asked.
2 Answers
Ryan Duchene
Courses Plus Student 46,022 PointsNo problem, man. Everyone has to start somewhere. :)
An argument is a piece of information that you give to a function. A function is an action; it goes and does something. An argument is an object that the function works with to accomplish something.
You can think of an argument as a secretary. You hand a letter to a secretary and say "Mail this."
<?php
function mail($letter)
{
// mails the $letter
}
You can make a function can take more than one arguments. You hand a letter and a stamp to the secretary and say "Put the stamp on the letter and mail it."
<?php
function mail($letter, $stamp)
{
// puts the $stamp on the $letter
// mails the $letter
}
The analogy isn't perfect, but it's the best I could come up with. So now, to actually stamp and mail your letter, you need to actually call the function.
<?php
mail($my_letter, $my_stamp);
Does that help you at all? I can try to simplify it if you want, or find a better analogy. It just takes time and practice to get used to these things, that's all. Treehouse is great with both. :)
jne
12,613 PointsAt php.net they have a manual to cover all you need to know about php. Here's a link about arguments http://php.net/manual/en/functions.arguments.php
Christian Andersson
8,712 PointsChristian Andersson
8,712 PointsGood answer and example.
I'd like to think of a function as a piece of code that is "cocooned" from any code that's outside of it. So if information from the main program needs to be given to this isolated piece of code it needs to be passed in the argument.
EDIT: Oh, and the people over at StackOverflow are usually #&!%