custom function but properties optional.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
.Stealth
Forum Commoner
Posts: 57
Joined: Wed Jan 10, 2007 12:15 pm
Location: Manchester, England

custom function but properties optional.

Post 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.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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...
.Stealth
Forum Commoner
Posts: 57
Joined: Wed Jan 10, 2007 12:15 pm
Location: Manchester, England

Post 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.
Post Reply