Page 1 of 1

[SOLVED] making a custom function argument optional

Posted: Tue Apr 05, 2005 6:12 am
by Skittlewidth
Quick question:

When writing a custom function that can take 3 arguments, how can I make the third argument optional?
The function itself works fine with just 2 arguments but PHP displays an error if I leave the 3rd one out.

Thanks!

Posted: Tue Apr 05, 2005 6:17 am
by CoderGoblin
Set a default value

Code: Select all

function myfunct($var1,$var2,$var3="")
{
}
Note optional parameters must all be on the end.

You may also want to look at http://www.php.net/manual/en/function.func-num-args.php
http://www.php.net/manual/en/function.func-get-args.php