Home  >  Article  >  Backend Development  >  php定义参数数量可变的函数用法实例_php技巧

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

WBOY
WBOYOriginal
2016-05-16 20:20:50999browse

本文实例讲述了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;>

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

Statement:
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