This article mainly introduces php variable length parameter processing functions, and analyzes the functions and usage of three variable length parameter processing functions, func_num_args (), func_get_arg (), and func_get_args (), in combination with examples, for more information about php variable length parameter processing functions, see the example in this article. We will share this with you for your reference. The details are as follows:
Like C ++, PHP can also process functions that contain variable parameters. The truth is the same. a function is required to process the parameter list. PHP provides three related functions:
1. func_num_args () -- Returns the number of parameters passed to the function.
int func_num_args ( void )
Example:
function open_database($DB, $cache_size_or_values=null, $cache_size=null){ switch (function_num_args()) { case 1: $r = select_db($DB); break; case 2: $r = select_db($DB, $cache_size_or_values); break; case 3: $r = select_db($DB, $cache_size_or_values, $cache_size); break; } return is_resource($r);}
2. func_get_arg () -- Return the specified parameter
mixed func_get_arg ( int arg_num)
The arg_num of the first parameter in the parameter list is 0.
3. func_get_args () -- returns the parameter list as an array.
array func_get_args ( void )
Example:
For more details about php variable length parameter processing functions, refer to the PHP Chinese network!