This article mainly introduces the PHP variable-length parameter processing function, and analyzes the functions and usage of the three variable-length parameter processing functions func_num_args(), func_get_arg() and func_get_args() combined with examples. Friends who need it can For reference,
is as follows:
Like C, functions containing variable parameters can also be processed in PHP. The principle is the same, and a function is needed to specifically 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)
<?php function some_func($a, $b) { for($i = 0; $i<func_num_args(); ++$i) { $param = func_get_arg($i); echo "the param is $param\n" } } some_func(1,3,5,7,9); ?>
3. func_get_args() -- Returns the parameter list in the form of an array
array func_get_args ( void )
<?php function some_other_func($a, $b) { $param = func_get_args(); $param = join(", ", $param); // 分解显示 echo "the arglist is: $param\n"; } some_other_func(1,3,5,7,9); ?>
$.ajax() method in JqueryParametersDetailed explanation
IE browser and FF browser about Ajax transmissionParameter The difference when the value is Chinese
ajax transmission ParametersQuick solution containing special characters
The above is the detailed content of Detailed explanation of variable length parameter processing function in PHP. For more information, please follow other related articles on the PHP Chinese website!