PHP function with unlimited number of parameters

后端 未结 8 1752
执念已碎
执念已碎 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:30

    Use func_get_args():

    function my_func() {
      $args = func_get_args();
      foreach ($args as $arg) {
        echo "Arg: $arg\n";
      }
    }
    

提交回复
热议问题