php函數(shù)指定默認值方法的小例子
本節(jié)內(nèi)容:
php函數(shù)指定默認值
在php編程中,為自定義函數(shù)設(shè)定默認值,當(dāng)用戶調(diào)用該函數(shù)時,如果不給參數(shù)指定值,參數(shù)會用默認值頂替。
例1,
<html>
<head>
<title>php函數(shù)指定默認值-www.dbjr.com.cn</title>
</head>
<body>
<?php
function printMe($param = NULL)
{
print $param;
}
printMe("This is test");
printMe();
?>
</body>
</html>
輸出結(jié)果:
This is test
例2,php函數(shù)參數(shù)默認值的使用范例,php函數(shù)參數(shù)中設(shè)置和使用默認值。
代碼:
<html>
<head>
<title>php函數(shù)參數(shù)默認值 - www.dbjr.com.cn</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>
相關(guān)文章
mysql查找刪除重復(fù)數(shù)據(jù)并只保留一條實例詳解
這篇文章主要介紹了mysql查找刪除重復(fù)數(shù)據(jù)并只保留一條實例詳解的相關(guān)資料,需要的朋友可以參考下2016-09-09codeigniter框架The URI you submitted has disallowed characters
這篇文章主要介紹了codeigniter框架The URI you submitted has disallowed characters錯誤解決方法,需要的朋友可以參考下2014-05-05php微信公眾號開發(fā)(2)百度BAE搭建和數(shù)據(jù)庫使用
這篇文章主要介紹了php微信公眾號開發(fā)第二課,百度BAE搭建和數(shù)據(jù)庫使用,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12