How do I set default value of function parameter as today's date?

4 replies
How do I set default value of function parameter as today's date?

I tried:
function funcName($today=date('Y-m-d')) {do something}

Throws me this error:
Parse error: syntax error, unexpected '(', expecting ')'

Thanks.
#date #default #function #parameter #set #today
  • Profile picture of the author ussher
    try:
    function funcName($today=false) {
    if(!$today){
    $today = date('Y-m-d');
    }

    //do something

    }
    Signature

    "Jamroom is a Profile Centric CMS system suitable as a development framework for building entire communities. Highly modular in concept. Suitable for enterprise level development teams or solo freelancers."

    - jamroom.net
    Download Jamroom free: Download
    {{ DiscussionBoard.errors[5641380].message }}
  • Profile picture of the author guava
    Just checking. Is this PHP?
    {{ DiscussionBoard.errors[5641892].message }}
  • Profile picture of the author guava
    Is this PHP?
    {{ DiscussionBoard.errors[5641896].message }}
  • Profile picture of the author KirkMcD
    If this is for PHP
    try:

    define('TODAY', date('Y-m-d'));
    function funcName($today=TODAY);
    {{ DiscussionBoard.errors[5641960].message }}

Trending Topics