PHP, how to pass func-get-args values to another function as list of arguments?

后端 未结 3 458
予麋鹿
予麋鹿 2020-12-29 20:38

I want to create a function (my_function()) getting unlimited number of arguments and passing it into another function (call_another_function()). <

相关标签:
3条回答
  • 2020-12-29 21:22

    Use call_user_func_array like

    call_user_func_array('another_function', func_get_args());
    
    0 讨论(0)
  • 2020-12-29 21:33

    It's not yet documented but you might use reflection API, especially invokeArgs.

    (maybe I should have used a comment rather than a full post)

    0 讨论(0)
  • 2020-12-29 21:43

    Try call_user_func_array:

    function my_function() {    
        $args = func_get_args();
        call_user_func_array("another_function", $args);
    }
    

    In programming and computer science, this is called an apply function.

    0 讨论(0)
提交回复
热议问题