PHP function with unlimited number of parameters

后端 未结 8 1711
执念已碎
执念已碎 2020-12-03 13:45

How do I write a function that can accept unlimited number of parameters?

What am trying to do is create a function within a class that wraps the following:

8条回答
  •  [愿得一人]
    2020-12-03 14:33

    Previously you should have used func_get_args(), but in the php 5.6, you can use ... operator.

    So for example you can write the function which returns you a sum of all the numbers, sent to the function:

    function bind_param(...$params){
       var_dump($params);
    }
    

    Your params is actually an array of all elements.

提交回复
热议问题