Unlimited arguments for PHP function?

后端 未结 4 2021
野性不改
野性不改 2020-12-10 05:56

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 w

4条回答
  •  不知归路
    2020-12-10 06:30

    Previously you should have used func_get_args(), but in a new php 5.6 (currently in beta), you can use ... operator instead of using .

    So for example you can write :

    function myFunc(...$el){
      var_dump($el); 
    }
    

    and $el will have all the elements you will pass.

提交回复
热议问题