views:

111

answers:

1

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?

+8  A: 

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.

cletus
hm nice - didn't know about this.
meder
Yeah, there are a ton of inbuilt functions in PHP. I'm still surprised at some I find.
cletus