获取参数信息:func_num_args和func_get_args
By Symphony - Last updated: Thursday, August 6, 2009 - Save & Share - One Comment
Examples
Example #1 func_get_args() example
function foo()
{
$numargs = func_num_args();
echo "Number of arguments: $numargs\n";
if ($numargs >= 2) {
echo "Second argument is: " . func_get_arg(1) . "\n";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "\n";
}
}
foo(1, 2, 3);
?>
The above example will output:
Number of arguments: 3 Second argument is: 2 Argument 0 is: 1 Argument 1 is: 2 Argument 2 is: 3
Comment from Symphony
Time 2009/08/19 at 11:08 pm
这个问题很多面试题都会问到的。