Page 1 of 1

custom function but properties optional.

Posted: Sat Jun 23, 2007 11:00 am
by .Stealth
hello, having a little trouble with a custom function.

i want the properties of it to be optional, by that i mean:

Code: Select all

function displayRegForm($username, $email, $ad1, $ad2, $ad3, $postcode){
}
the variables between the () i would like to be optional so i dont get the undefined variable notice.

how can i say that, or cant i?
ive looked on the manual but cant see anything.

thanks.

Posted: Sat Jun 23, 2007 11:06 am
by Oren

Code: Select all

function my_func($var1 = '', $var2 = 0, $var3 = false, $var4 = 'this is a default value') {...}
You just give each one of them a default value - an empty string, 0, false or anything else...

Posted: Sat Jun 23, 2007 11:18 am
by .Stealth
Oren wrote:

Code: Select all

function my_func($var1 = '', $var2 = 0, $var3 = false, $var4 = 'this is a default value') {...}
You just give each one of them a default value - an empty string, 0, false or anything else...

ohh ok then, i didnt know you could set values there :D

thanks for your help.