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
func_get_args();
Example
Get all arguments passed to the function:
<?php
function test() {
$res = func_get_args();
print_r($res);
}
test(1, 2, 3);
?>
Code execution result:
[1, 2, 3]
Example
Usage with different argument types:
<?php
function showArgs() {
$res = func_get_args();
print_r($res);
}
showArgs('a', 1, true, null);
?>
Code execution result:
['a', 1, true, null]
Example
Getting arguments without declaring parameters:
<?php
function sum() {
$args = func_get_args();
return array_sum($args);
}
echo sum(5, 10, 15);
?>
Code execution result:
30
See Also
-
the
func_num_argsfunction,
which returns the number of arguments passed -
the
func_get_argfunction,
which returns a specific argument by index