时间:2021-07-01 10:21:17 帮助过:22人阅读
php中的的函数参数可以不固定,甚至不用定义参数,在函数内部使用func_get_args()函数获得参数列表,调用时可以为函数指定任意参数,非常方便
<?php
function addanything (){
$total = 0;
$args = func_get_args ();
for ($i = 0; $i < count ($args); $i++){
if (is_int ($args[$i])){
$total += $args[$i];
}
}
return $total;
}
echo addanything (1,5,7,8,11) . "
";
?>
希望本文所述对大家的php程序设计有所帮助。