Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does php have something similar to javascript's arguments variable [duplicate]

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?

like image 598
wheresrhys Avatar asked Jan 18 '23 14:01

wheresrhys


1 Answers

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 />
like image 53
Mariusz Jamro Avatar answered Jan 30 '23 22:01

Mariusz Jamro