Re: Default parameter
.oO(Mike)
>If possible, how do I use a function to create a default parameter
>value? The following gives me an "unexpected '(', expecting ')'"
>error, which makes sense.
>
>function DisplayInfo($ID, $startdate=date("Ydm"), $numdays=7) {
> ...function here...
>}
Default arguments have to be constant values, no variables or function
calls. You could use something like this:
function DisplayInfo($ID, $startdate = NULL, $numdays = 7) {
if (is_null($startdate)) {
$startdate = date('Ydm');
}
...
}
Micha
|