php 函数func_get_args()、func_get_arg()与func_num_args()之间的比较

func_get_args():返回一个包含函数参数列表的数组。 
func_get_arg():返回指定的参数值。 
func_num_args():返回调用函数的传入参数个数,类型是整型。

举个小栗子方便大家更容易的理解这几个函数呦

<?php
class test{
    public function hello($a,$b,$c,$d){
        $num=func_num_args();
        echo "方法参数的个数为:".$num,"<br>";
        if(2<=$num){
            echo "方法的第三个参数为:".func_get_arg(2)."<br>";
        }
        $num2=func_get_args();
//        print_r($num2);exit;
        for($i=0;$i<$num;$i++){
            echo "第{$i}个参数为{$num2[$i]}"."<br>";
        }
    }
}

$T=new test();
$T->hello('A','B','C','D');

?>

下面是返回:

方法参数的个数为:4
方法的第三个参数为:C
第0个参数为A
第1个参数为B
第2个参数为C
第3个参数为D

猜你喜欢

转载自blog.csdn.net/li_lening/article/details/81138627
今日推荐