func_get_arg()

func_get_arg() — Return an item from the argument list.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Gets the specified argument from a user-defined function's argument list.

Signature

func_get_arg(int $position): mixed

Parameters

ParameterTypeWhat it takes
$positionintThe argument offset. Function arguments are counted starting from zero.

Return value

Returns the specified argument, or false on error.

Example

A runnable snippet:

function foo() { $numargs = func_num_args(); echo "Number of arguments: $numargs\n"; if ($numargs >= 2) { echo "Second argument is: " . func_get_arg(1) . "\n"; } } foo(1, 2, 3);

Output:

Number of arguments: 3 Second argument is: 2

See also

func_get_args(), func_num_args()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page func_get_arg() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.