Home > php教程 > php手册 > php定义参数数量可变的函数用法实例

php定义参数数量可变的函数用法实例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 09:11:55
Original
1226 people have browsed it

php定义参数数量可变的函数用法实例

 这篇文章主要介绍了php定义参数数量可变的函数用法,实例分析了func_get_args的使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下

 

 

本文实例讲述了php定义参数数量可变的函数用法。分享给大家供大家参考。具体分析如下:

php中的的函数参数可以不固定,甚至不用定义参数,在函数内部使用func_get_args()函数获得参数列表,调用时可以为函数指定任意参数,非常方便

?

1

2

3

4

5

6

7

8

9

10

11

12

13

function addanything (){

$total = 0;

$args = func_get_args ();

for ($i = 0; $i

if (is_int ($args[$i])){

$total += $args[$i];

}

}

return $total;

}

echo addanything (1,5,7,8,11) . "
";

?>

希望本文所述对大家的php程序设计有所帮助。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template