3

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?

0

1 Answer 1

10

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.