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!
[SOLVED] making a custom function argument optional
Moderator: General Moderators
- Skittlewidth
- Forum Contributor
- Posts: 389
- Joined: Wed Nov 06, 2002 9:18 am
- Location: Kent, UK
[SOLVED] making a custom function argument optional
Last edited by Skittlewidth on Tue Apr 05, 2005 8:57 am, edited 2 times in total.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Set a default value
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
Code: Select all
function myfunct($var1,$var2,$var3="")
{
}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