This article describes the usage of a PHP function definition with a variable number of parameters. Share it with everyone for your reference. The specific analysis is as follows:
The function parameters in php do not need to be fixed, and there is no need to even define parameters. Use the func_get_args() function inside the function to obtain the parameter list. You can specify any parameters for the function when calling, which is very convenient
<?php function addanything (){ $total = 0; $args = func_get_args (); for ($i = 0; $i < count ($args); $i++){ if (is_int ($args[$i])){ $total += $args[$i]; } } return $total; } echo addanything (1,5,7,8,11) . "<br />"; ?>
I hope this article will be helpful to everyone’s PHP programming design.