Is there a way to get the parameters passed to a php function?
fill in the blank if its possible:
function foo(){
var_dump( SOME_MAGICAL_FUNCTION_THAT_GETS_ALL_PARAMETERS_INTO_AN_ARRAY );
}
foo('a', 'b', 'c', 1, 2, 3);
Is there a way to get the parameters passed to a php function?
fill in the blank if its possible:
function foo(){
var_dump( SOME_MAGICAL_FUNCTION_THAT_GETS_ALL_PARAMETERS_INTO_AN_ARRAY );
}
foo('a', 'b', 'c', 1, 2, 3);
是的,使用 PHP 的内置函数func_get_args()
这是 PHP 文档中的一个示例:
function foo()
{
$numargs = func_num_args();
echo "Number of arguments: $numargs<br />\n";
if ($numargs >= 2) {
echo "Second argument is: " . func_get_arg(1) . "<br />\n";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
}
}
foo(1, 2, 3);
func_get_args()正是这样做的。