Is it possible to convert a list of PHP function parameters to an array?

Suppose I have a function:

function my_function($a, $b, $c) {
    ...
}

I want to be able to play with my parameter list, as if it were an array - like here, using a fake variable $parameter_list:

function my_function($a, $b, $c) {
    foreach ($parameter_list as $value) {
        print $value."\n";
    }
    ...
}

How can i do this?

+3
source share
1 answer

Just call func_get_args().

It is usually used for user-defined functions that have a variable number of arguments, but there is no reason why you cannot use it for a "normal" function.

This returns the numerical index of the function arguments. Cannot return parameter names.

+10

Source: https://habr.com/ru/post/1717600/


All Articles