(转载)func_get_args()函数
(转载)http://www.cnblogs.com/yuxing/articles/1755659.html
获取一个函数的所有参数
例子:
<?php function foo() { $numargs = func_num_args(); //参数数量 echo "参数个数是: $numargs<br />\n"; if ($numargs >= 2) { echo "第二个参数的值:" . func_get_arg(1) . "<br />\n"; } $arg_list = func_get_args(); for ($i = 0; $i < $numargs; $i++) { echo "第{$i}个参数值:{$arg_list[$i]}<br />\n"; } } foo(1, 'd', 3,4); ?>
程序输出:
参数个数是: 4 第二个参数的值:d 第0个参数值:1 第1个参数值:d 第2个参数值:3 第3个参数值:4
例子:
<?php sayPositive("The", "day", "is", "beautiful!"); function sayPositive() { $args = func_get_args(); // 获取函数参数 echo implode(' ', $args).'<br>'; } ?>
程序输出:
The day is beautiful!