01-20-2008, 10:39 AM
|
#4 (permalink)
|
|
The Frequenter
Join Date: Apr 2005
Location: South UK
Posts: 483
Thanks: 51
|
Hi Sarmenhb,
There are a couple of ways to achieve what you want:
The first is to provide your function with a default value in the event that one isn't provided - see Xenon's example. In this case, he has set the default value to NULL, then checks against that in the function.
The second way is to use func_num_args() as you tried:
PHP Code:
function br()
{
$numargs = func_num_args();
if ($numargs == 0)
{
die('You must provide a number!');
}
else
{
$num = func_get_args(0); // Gets the first argument
echo "You provided $num !";
}
}
This method also allows you to accept an unknown number of arguments if your function needs it.
Alan
|
|
|