聘我网

新概念招聘3.0

PHP中函数的可变参数如何写?

vote up0vote downstar

可以接受任意个参数的函数

 

1 个答复

vote up0vote downcheck

函数定义中不写形参,然后用func_num_argsfunc_get_args获取参数个数以及具体的参数。

例:

function test()
{
    $total = func_num_args();
    $numbers = func_get_args();
    var_dump($total);
    var_dump($numbers);
}
test(1,2);
链接

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.