I know how to check with func_num_args
for the number of arguments for a function, but how can I get these arguments inside the php function:
<?php
function test() {
echo func_num_args(); //returns 2
echo $argv[1]; //this doesn't work
}
test("aa","bb");
?>
You can call func_get_args()
to obtain the array of arguments passed to the function.
For your example, simply add
$args = func_get_args();
And it should work as intended.
There also is func_get_arg
, which returns a single argument:
echo func_get_arg(1); // prints second argument
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments