如何一次拿到php函数中的所有参数的实参值?

来源:互联网 发布:yes淘宝刷信用 编辑:程序博客网 时间:2024/05/18 18:00
<?phpfunction demo($num1,$num2,$num3,$num4,$num5=''){// 只是调用的个数,实参echo "the all parameter 's sum is ".$numargs=func_num_args()."<br>" ;//返回指定位置参数值 ,超出会报错  func_get_arg(): Argument 31 not passed to function in 。。。echo func_get_arg(3)."<br>";// 得到实参数组$arg_list = func_get_args();    for ($i = 0; $i < $numargs; $i++) {        echo "the  parameter {$i} 's value is " .$arg_list[$i]."<br />\n";    }return ($num1+$num2)-$num3*$num4;}echo demo(1,2,2,4);


output:

the all parameter 's sum is 4
4
the parameter 0 's value is 1
the parameter 1 's value is 2
the parameter 2 's value is 2
the parameter 3 's value is 4
-5

0 0
原创粉丝点击