func_get_arg
Description
The func_get_arg of Function Handling for PHP returns an item from the argument list.
Syntax
func_get_arg(
int $position
): mixedParameters
position
The argument offset. Function arguments are counted starting from zero.
Return
Returns the specified argument, or false on error.
Examples
1 · position
<?
function myfunction()
{
$position = 1;
$return = func_get_arg($position);
echo $return . PHP_EOL;
}
myfunction("a", "b", "c");
myfunction("d", "e", "f", "g");
myfunction("h", "i");
b e i
2 · for
<?
function myfunction()
{
$number = func_num_args();
for($i = 0; $i < $number; ++$i)
{
$position = $i;
$return = func_get_arg($position);
echo $position . ": " . $return . PHP_EOL;
}
echo PHP_EOL;
}
myfunction("a", "b", "c");
myfunction("d", "e", "f", "g");
myfunction("h", "i");
0: a 1: b 2: c 0: d 1: e 2: f 3: g 0: h 1: i