background image

深圳市一览网络股份有限
公司
ShenZhen Elanw Network 

Co.,Ltd.

地址:南山科技园南区数字技术园
B2 栋 4A 
Add: Room A,4th Floor,Block 
B2,Digi-Tech Park ,

电话(Tel):0755-86133725
传真(Fax):0755-22632616
网址
(Web):www.YL1001.com

 

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

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>