Page 1 of 1

Make Parameter Optional

Posted: Wed May 25, 2011 6:25 pm
by unemployment
How do I make a function parameter optional?

Re: Make Parameter Optional

Posted: Wed May 25, 2011 6:28 pm
by jacek
Give it a default value in the definition
function I_am_a_function($first, $second = true){
    // things
}
if no value is given for the second parameter, the code inside the function will see it as true.

Re: Make Parameter Optional

Posted: Wed May 25, 2011 6:31 pm
by unemployment
jacek wrote:Give it a default value in the definition
function I_am_a_function($first, $second = true){
    // things
}
if no value is given for the second parameter, the code inside the function will see it as true.
I assume I can set = null

Re: Make Parameter Optional

Posted: Wed May 25, 2011 6:33 pm
by unemployment
yay... you can

Re: Make Parameter Optional

Posted: Wed May 25, 2011 6:58 pm
by jacek
unemployment wrote:yay... you can
:lol:

I think you can set = pretty much anything.