PHP supports a variable number of parameter lists in user-defined functions. It's really simple, just use
Func_num_args () ,
func_get_arg () , and the
Func_get_args () function. mutable parameters do not require special syntax, and parameter lists are still passed to the function as defined by the function and are used in the usual way.
1.func_num_args
-Returns the total number of arguments passed in the function
int Func_num_args (void)
Example
<?phpfunction Demo () { $numargs = Func_num_args (); echo "Number of parameters: $numargs \ n";} Demo (' A ', ' B ', ' C ');
Run Results
Number of parameters: 3
2.func_get_args-Returns the argument list of the passed-in function
Array Func_get_args (void)
Example
<?phpfunction Demo () { $args = Func_get_args (); echo "Incoming parameters are:"; Var_dump ($args);} Demo (' A ', ' B ', ' C ');
Run results
The parameters passed are: Array (size=3) 0 = = String ' A ' (length=1) 1 = string ' B ' (length=1) 2 = = String ' C ' (len gth=1)
3.func_get_arg-returning parameter values from the parameter list based on the parameter index
Mixed func_get_arg (int $arg _num )
Example
<?phpfunction Demo () { $numargs = Func_num_args (); echo "Number of parameters: $numargs <br/>"; $args = Func_get_args (); if ($numargs >= 2) { echo "The second parameter is:" . Func_get_arg (1). " <br/> "; }} Demo (' A ', ' B ', ' C ');
Run Results
The number of parameters is: 3 The second parameter is: b
PHP Dynamic Get function parameters