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.
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.
Try:
function func_name($date = null)
{
if(is_null($date))
$date = date('Y-m-d');
// Your code here
}
From the manual (below example #4): "The default value must be a constant expression, not (for example) a variable, a class member or a function call."
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.