Reply
Optional arguments in functions
Old 06-27-2008, 07:15 PM Optional arguments in functions
KkillgasmM's Avatar
Ultra Talker

Posts: 361
Name: El Phantasmo
Location: England, north west
Im creating a function that has an argument, but I want the argument to be optional!

Does anyone know how I would do this?
__________________
New Portfolio
KkillgasmM is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 06-27-2008, 08:10 PM Re: Optional arguments in functions
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
PHP Code:
function myFunction($argument_1 'default') {

Just assign it a default value
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 06-27-2008, 08:20 PM Re: Optional arguments in functions
KkillgasmM's Avatar
Ultra Talker

Posts: 361
Name: El Phantasmo
Location: England, north west
ahhh simple! Thanks
__________________
New Portfolio
KkillgasmM is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 09:23 AM Re: Optional arguments in functions
KkillgasmM's Avatar
Ultra Talker

Posts: 361
Name: El Phantasmo
Location: England, north west
Hmmm do you know how I would go about getting this to work?

PHP Code:
function myDate ($stamp time())
    { 
But I get this error:

Quote:
Parse error: syntax error, unexpected '(', expecting ')' in C:\xampp\htdocs\xampp\mattPealingDesign\script\php \myDate.php on line 5
__________________
New Portfolio
KkillgasmM is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 11:31 AM Re: Optional arguments in functions
wayfarer07's Avatar
$frontend->developer

Posts: 1,032
Name: Abel Mohler
Location: Asheville, North Carolina USA
How about this?
PHP Code:
$time time();
function 
myDate($stamp $time) { 
__________________
Go FREELANCE <=|If a donkey eats a melon, it is still a donkey... |=> Hire Me
wayfarer07 is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 12:28 PM Re: Optional arguments in functions
KkillgasmM's Avatar
Ultra Talker

Posts: 361
Name: El Phantasmo
Location: England, north west
Thanks but that doesn't work either!

Quote:
Parse error: syntax error, unexpected T_VARIABLE
__________________
New Portfolio
KkillgasmM is offline
Reply With Quote
View Public Profile
 
Old 06-28-2008, 01:32 PM Re: Optional arguments in functions
wayfarer07's Avatar
$frontend->developer

Posts: 1,032
Name: Abel Mohler
Location: Asheville, North Carolina USA
do this:
PHP Code:
function myDate($stamp "") {
if(empty(
$stamp)) {
$stamp time();

__________________
Go FREELANCE <=|If a donkey eats a melon, it is still a donkey... |=> Hire Me
wayfarer07 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Optional arguments in functions
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15095 seconds with 12 queries