Php defines a variable number of function usage instances. Example of function usage with variable number of php defined parameters this article mainly introduces the function usage with variable number of php defined parameters. The example shows how to use func_get_args, examples of function usage with variable number of parameters defined by reference to php
This article mainly introduces the usage of php functions with variable number of defined parameters. The example analyzes the usage skills of func_get_args, which has some reference value. For more information, see
This example describes how to use a function that defines variable number of parameters in php. Share it with you for your reference. The specific analysis is as follows:
The function parameters in php can be unfixed or even need not be defined. in the function, use the func_get_args () function to obtain the parameter list. you can specify any parameter for the function during the call, which is very convenient.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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 )." "; ?> |
I hope this article will help you with php programming.
This article describes how to use a function that defines variable number of parameters in php. The example analyzes the usage skills of func_get_args...