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

phpfunc_get_arg(int $index);

Example

Get the first argument (index 0) from those passed to the function:

php<?php
  function test() {
    $res = func_get_arg(0);
    echo $res;
  }
  test('abcde');
?>

Code execution result:

php'abcde'

Example

Get the second argument (index 1) from the passed parameters:

php<?php
  function testArgs() {
    $res = func_get_arg(1);
    return $res;
  }
  echo testArgs(1, 2, 3);
?>

Code execution result:

php2

See Also

  • the func_get_args function,
    which returns all function arguments as an array
  • the func_num_args function,
    which returns the number of arguments passed