This article mainly introduces the PHP definition parameter quantity variable function usage, the example analysis Func_get_args's use skill, has certain reference value, the need friend may refer to under
The examples in this article describe the functional usage of PHP's variable number of defined parameters. Share to everyone for your reference. The specific analysis is as follows:
PHP in the function parameters can not be fixed, or even the definition of parameters, within the function using the Func_get_args () function to obtain a list of parameters, call can specify any parameters for the function, very convenient
?
1 2 3 4 5 6 7 8 9 10 11 12-13 |
<?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 help you with your PHP program design.