并不需要特别的语法,参数列表仍按函数定义的方式传递给函数,并按通常的方式使用这些参数。
1.func_num_args — 返回传入总个数
int func_num_args ( void )
示例
<?php
function  demo ()
{
    $numargs  =  func_num_args ();
    echo  "参数个数为:  $numargs 
" ;
}
demo ( 'a' ,  'b' ,  'c' );
?>运行结果
参数个数为: 3
2.func_get_args — 返回传入函数的参数列表
array func_get_args ( void )
示例
<?php
function  demo ()
{
    $args = func_get_args();
    echo "传入的参数分别为:";
    var_dump($args);
}
demo ( 'a' ,  'b' ,  'c' );
?>运行结果
传入的参数分别为: array (size=3) 0 => string 'a' (length=1) 1 => string 'b' (length=1) 2 => string 'c' (length=1)
3.func_get_arg — 根据参数从参数列表返回参数值
mixed func_get_arg ( int $arg_num )
示例
<?php
function  demo ()
{
    $numargs  =  func_num_args ();
    echo  "参数个数为:  $numargs <br />" ;
    $args = func_get_args();
    if ( $numargs  >=  2 ) {
        echo  "第二个参数为: "  .  func_get_arg ( 1 ) .  "<br />" ;
    }
}
demo ( 'a' ,  'b' ,  'c' );
?>运行结果
参数个数为: 3 第二个参数为: b
| 欢迎光临 一起源码网 (https://www.171739.xyz/) | Powered by Discuz! X3.3 |