5

Possible Duplicate:
PHP get all arguments as array?

Within a javascript function arguments always points to to an array-like object containing the function's parameters. Does php have something similar so I can easily var_dump() all a function's arguments?

0

2 Answers 2

7

Function func_get_args would do the trick.

<?php
function foo()
{
    $numargs = func_num_args();
    echo "Number of arguments: $numargs<br />\n";
    if ($numargs >= 2) {
        echo "Second argument is: " . func_get_arg(1) . "<br />\n";
    }
    $arg_list = func_get_args();
    for ($i = 0; $i < $numargs; $i++) {
        echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
    }
}

foo(1, 2, 3);
?>

The above example will output:

Number of arguments: 3<br />
Second argument is: 2<br />
Argument 0 is: 1<br />
Argument 1 is: 2<br />
Argument 2 is: 3<br />
Sign up to request clarification or add additional context in comments.

Comments

2

Yep, func_get_args().

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.