Heim  >  Artikel  >  php教程  >  php指定函数参数默认值示例代码

php指定函数参数默认值示例代码

WBOY
WBOYOriginal
2016-06-06 20:26:141115Durchsuche

在php编程中,为自定义函数设定默认值,当用户调用该函数时,如果不给参数指定值,参数会用默认值顶替,下面看例子

例1

复制代码 代码如下:




php函数指定默认值-


function printMe($param = NULL)
{
   print $param;
}
printMe("This is test");
printMe();
?>



输出结果:
This is test

例2 php函数参数默认值的使用范例,php函数参数中设置和使用默认值。

复制代码 代码如下:



 


  php函数参数默认值 -
 
 
    function textonweb ($content, $fontsize=3){
     echo "$content";
  }
  textonweb ("A
", 7);
  textonweb ("AA.
");
  textonweb ("AAA.
");
  textonweb ("AAAA!
");
  ?>
 
 
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn