您的位置:首页 > 编程语言 > PHP开发

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

2013-12-04 00:00 741 查看
例1

<html>
<head>
<title>php函数指定默认值-www.jb51.net</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.jb51.net</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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: