Is there a way to allow a function to accept an indefinite number of arguments?
I have a function that can potentially accept millions of arguments. Currently, I am using an array to insert into it, but I think it would be 开发者_如何转开发more friendly to have an indefinite number of arguments. Is this possible?
func_get_args()
is what you're looking for
function sumValues() {
$result = 0;
foreach(func_get_args() as $arg) {
$result += $arg;
}
return $result;
}
echo sumValues(1,2,3,4);
精彩评论