Fragsworth
Fragsworth

Reputation: 35497

Is it possible to convert a PHP function's parameter list 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 - as with here, using a fake $parameter_list variable:

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

How can I do this?

Upvotes: 3

Views: 336

Answers (1)

cletus
cletus

Reputation: 625097

Just call func_get_args().

It's normally used for user-defined functions that have a variable number of arguments but there's no reason you can't use it for a "normal" function.

This returns a numerically-indexed array of function arguments. There is no way of returning the parameter names.

Upvotes: 10

Related Questions