What is the good example of using 'func_get_arg' in PHP?

后端 未结 7 1444
梦谈多话
梦谈多话 2021-02-07 00:39

I just have found out that there is a function called func_get_arg in PHP which enables developer to use variant style of getting arguments. It seems to be very us

7条回答
  •  不要未来只要你来
    2021-02-07 01:00

    I usually use func_get_args() which is easier to use if wanting multiple arguments.

    For example, to recreate PHP's max().

    function max() {
       $max = -PHP_INT_MAX;
       foreach(func_get_args() as $arg) {
          if ($arg > $max) {
              $max = $arg;
          }
       }
       return $max;
    }
    

    CodePad.

    Now you can do echo max(1,5,7,3) and get 7.

提交回复
热议问题