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

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

WBOY
Release: 2016-06-13 09:12:00
Original
1001 people have browsed it

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

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

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

<&#63;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) . "<br />";
&#63;>
Copy after login

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

Related labels:
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template