View Single Post

  #4 (permalink)  
Old 11-16-2004
Mike
 
Posts: n/a
Default Re: Default parameter

Thanks for clearing that up. I ended up using '$startdate="blurgh"'

if ($startdate="blurg"){
$startdate=date("Ymd");
}

Michael Fesser <netizen@gmx.net> wrote in message news:<9diip01h7eqforq6e8h0ucmr6sk7tl29jq@4ax.com>. ..
> .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

Reply With Quote