The func_get_args Function

The func_get_args function allows you to get all arguments passed to a function as an array. It does not accept parameters and should be called only inside custom functions.

Syntax

phpfunc_get_args();

Example

Get all arguments passed to the function:

php<?php
  function test() {
    $res = func_get_args();
    print_r($res);
  }
  test(1, 2, 3);
?>

Code execution result:

php[1, 2, 3]

Example

Usage with different argument types:

php<?php
  function showArgs() {
    $res = func_get_args();
    print_r($res);
  }
  showArgs('a', 1, true, null);
?>

Code execution result:

php['a', 1, true, null]

Example

Getting arguments without declaring parameters:

php<?php
  function sum() {
    $args = func_get_args();
    return array_sum($args);
  }
  echo sum(5, 10, 15);
?>

Code execution result:

php30

See Also

  • the func_num_args function,
    which returns the number of arguments passed
  • the func_get_arg function,
    which returns a specific argument by index