开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜