How do I write a function that can accept unlimited number of parameters?
What am trying to do is create a function within a class that wraps the following:
If you are using PHP 5.6 or later version, argument lists may include the ...
token to denote that the function accepts a variable number of arguments. The arguments will be passed into the given variable as an array; Simply Using ...
you can access unlimited variable arguments.
for example:
If you are using PHP version <= 5.5 then you can access unlimited parameterusing the func_num_args(), func_get_arg(), and func_get_args() functions.
For example:
= 2) {
echo "Second argument is: " . func_get_arg(1) . "\n";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "\n";
}
}
foo(1, 2, 3);
?>