Home  >  Article  >  Backend Development  >  func_get_args() func_get_arg(offset) func_num_args(); Function usage_PHP tutorial

func_get_args() func_get_arg(offset) func_num_args(); Function usage_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:10:07789browse

func_get_args is an array for getting the parameters in the method. It returns an array and is used with func_num_args;

func_get_arg is the parameter to get the specified offset


func_num_args counts the number of parameters


func_num_args is generally written in a method and is used for counting;
How to use:
[php]
function myargs($a='para1',$b='para2'){
$numargs = func_num_args();
echo "Number of parameters : $numargs
n";
If ($numargs >= 2) {
echo "Second parameters is: " . func_get_arg(1) . "
n";
}  
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "parameters $i is: " . $arg_list[$i] . "
n";
}  
}

myargs(11, 22);
Will output:
Number of parameters : 2
Second parameters is: 22
parameters 0 is: 11
parameters 1 is: 22

function myargs($a='para1',$b='para2'){
$numargs = func_num_args();
echo "Number of parameters : $numargs
n";
If ($numargs >= 2) {
echo "Second parameters is: " . func_get_arg(1) . "
n";
}
$arg_list = func_get_args();
for ($i = 0; $i < $numargs; $i++) {
echo "parameters $i is: " . $arg_list[$i] . "
n";
}
}

myargs(11, 22);
Will output:
Number of parameters : 2
Second parameters are: 22
parameters 0 is: 11
parameters 1 is: 22

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477547.htmlTechArticlefunc_get_args is to get the array of parameters in the method. What is returned is an array, used in conjunction with func_num_args; func_get_arg is to get the specified Offset parameter func_num_args statistical parameters...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn