Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

func_get_args

Returns every argument passed to the function.

Syntax

func_get_args(): array

Return value

arrayAn array of the arguments.

Examples

The old and the modern form:

<?php
 
function sumOld()
{
    return array_sum(func_get_args());
}
 
function sumNew(int ...$numbers): int
{
    return array_sum($numbers);
}
 
echo sumOld(1, 2, 3), ' ', sumNew(1, 2, 3);

Output:

6 6

Notes

In new code use a parameter with three dots: it is visible in the signature and can carry a type.

See also

  • call_user_func_array — Calls a function, passing the arguments as an array.
  • array_sum — Returns the sum of the values in an array.
  • count — Returns the number of elements in an array.

In the tutorial

  • More about functions — Named arguments, variable-length argument lists, passing by reference, static variables and recursion in PHP.

Thanks for reading!

Donate to the site — we work hard for you.