Page 1 of 1

Optional function variable[Solved]

Posted: Thu Mar 03, 2005 7:07 am
by AGISB
I want something like

Code: Select all

function test ($var) {
}
but var should be optional. if I call text() it gives a required argument error.

Is there a way to archive this?

Posted: Thu Mar 03, 2005 7:15 am
by CoderGoblin
You need to set a default value such as...

Code: Select all

function test ($var="") {
  //function body
}
Optional vars should be placed after required arguments, not mixed.

You could also use
:arrow: http://www.php.net/manual/en/function.func-num-args.php and
:arrow: http://www.php.net/manual/en/function.func-get-args.php


feyd | ;)