The func_get_arg Function
The func_get_arg function returns the specified argument from the list of parameters passed to the function. It accepts the argument index as a parameter (starting from 0). This function must be called only inside a user-defined function.
Syntax
func_get_arg(int $index);
Example
Get the first argument (index 0) from those passed to the function:
<?php
function test() {
$res = func_get_arg(0);
echo $res;
}
test('abcde');
?>
Code execution result:
'abcde'
Example
Get the second argument (index 1) from the passed parameters:
<?php
function testArgs() {
$res = func_get_arg(1);
return $res;
}
echo testArgs(1, 2, 3);
?>
Code execution result:
2
See Also
-
the
func_get_argsfunction,
which returns all function arguments as an array -
the
func_num_argsfunction,
which returns the number of arguments passed