PHP Extracurricular notes--implementation of variable parameter list of function PHP is very powerful in terms of functions, but for some novice PHP, understanding is part of the difficulty, not fully mastered.
In the PHP training tutorial, we introduce the implementation of a variable parameter list of functions:
The implementation of the variable parameter list of PHP functions is mainly implemented by using the three system functions of Func_get_args (), Func_num_args (), Func_get_arg (), where the Func_get_args () function obtains the parameter list in the form of an array , refer to the manual for specific usage.
The PHP function variable argument list code is as follows:
< PHP
/* Implementation of the multi-parameter list of functions */
function Multiargs ()
{
/** returns the list of parameters as an array */
$args = Func_get_args ();
Number of/** parameters */
$args _num = Func_num_args ();
foreach ($args as $key = $value)
{
Echo ' This is ', $key +1, ' th argument: ', $value, ' <br/> ';
}
Echo ' number of args is ', $args _num;
}
Multiargs (' One ', ' one ', ' one ', ' three ');
/** Output */
/**
This is 1th Argument:one
This is 2th Argument:two
This is 3th argument:three
Number of args is 3
*/
?> (Hefei Open Source It education example code)
The above is the implementation method of the variable parameter list of PHP function
This article comes from: PHP training, open source it education, open source it education and training
PHP Extracurricular notes--implementation of variable parameter list of function