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

前端技术 2023/09/06 PHP

例1

复制代码 代码如下:

<html>
<head>
<title>php函数指定默认值-www.phpstudy.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.phpstudy.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>

本文地址:https://www.stayed.cn/item/16859

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。