无限论据PHP函数? [英] Unlimited arguments for PHP function?
问题描述
在PHP中你将如何创建一个可以采取无限数量的参数的函数: myFunc的($ P1,P2 $,$ P3,P4 $,$ P5 ...);
我的下一个问题是:你会如何将它们传递到另一个功能类似于
函数myFunc的($ params)方法{
anotherFunc($ params)方法;
}
但 anotherFunc
将接受他们,如果它是使用名为 anotherFunc($ P1,$ P2,$ P3,$ P4,$ P5 ...)
call_user_func_array('anotherFunc',func_get_args());
func_get_args
返回包含传递给它从调用的函数,并且所有的参数 call_user_func_array
调用一个给定的数组函数,传入的参数数组。
In php how would you create a function that could take an unlimited number of parameters: myFunc($p1, $p2, $p3, $p4, $p5...);
My next question is: how would you pass them into another function something like
function myFunc($params){
anotherFunc($params);
}
but the anotherFunc
would receive them as if it was called using anotherFunc($p1, $p2, $p3, $p4, $p5...)
call_user_func_array('anotherFunc', func_get_args());
func_get_args
returns an array containing all arguments passed to the function it was called from, and call_user_func_array
calls a given function, passing it an array of arguments.
这篇关于无限论据PHP函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!