龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

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

时间:2014-06-01 02:21来源:网络整理 作者:网络 点击:
分享到:
在php编程中,为自定义函数设定默认值,当用户调用该函数时,如果不给参数指定值,参数会用默认值顶替,下面看例子

例1

代码如下:

<html>
<head>
<title>php函数指定默认值-www.jbxue.com</title>
</head>
<body>
<?php
function printMe($param = NULL)
{
   print $param;
}
printMe("This is test");
printMe();
?>

</body>
</html>

输出结果:
This is test

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

代码如下:

<html>
  <head>
  <title>php函数参数默认值 - www.jbxue.com</title>
  </head>
  <body>
  <?php
  function textonweb ($content, $fontsize=3){
     echo "<font SIZE=$fontsize>$content</font>";
  }
  textonweb ("A <br />", 7);
  textonweb ("AA.<br />");
  textonweb ("AAA. <br />");
  textonweb ("AAAA! <br />");
  ?>
  </body>
  </html>

精彩图集

赞助商链接