Home >php教程 >php手册 >func_get_args() func_get_arg(offset) func_num_args(); 函数使用

func_get_args() func_get_arg(offset) func_num_args(); 函数使用

WBOY
WBOYOriginal
2016-06-13 10:56:09826browse

func_get_args是获取方法中参数的数组,返回的是一个数组,与func_num_args搭配使用;

func_get_arg是获取指定偏移量的参数


func_num_args统计参数个数


func_num_args一般写在方法中,用于计数;
使用方法如下:
[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          echo "parameters $i is: " . $arg_list[$i] . "
\n"; 
     } 

 
myargs(11, 22);    
将会输出: 
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          echo "parameters $i is: " . $arg_list[$i] . "
\n";
     }
}

myargs(11, 22);  
将会输出:
Number of parameters : 2
Second parameters is: 22
parameters 0 is: 11
parameters 1 is: 22

 

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