Home >php教程 >php手册 >php入门学习知识点七 PHP函数的基本应用

php入门学习知识点七 PHP函数的基本应用

WBOY
WBOYOriginal
2016-06-13 12:07:37860browse

复制代码 代码如下:


/*
* 简单的函数
*/
function fontBold($con){
return "$con";
}
$str="简单的函数测试!";
echo "普通文本:$str
";
echo "加粗文本:".fontBold($str)."";
/*
* 带可选参数的函数
*/
function fontColor($con,$color="bule"){
return "$con";
}
$str="颜色测试";
echo $str;
echo fontColor($str."这是不带颜色参数的(默认为蓝色)!");
echo fontColor($str,"red"."这是带颜色参数的(默认为红色!)");
/*
* 递归函数
*/
function chckint($Num){
if($Num>1){
return chckint($Num-1);
}else if($Numreturn chckint(($Num*-1)-1);
}else{
if($Num>0 && $Numreturn false;
}else if($Num){
return true;
}
}
}
$Num=3;
if(chckint($Num)){
echo $Num."是整数!";
}else{
echo $Num."不是整数";
}
/*
*动态调用函数
*/
function write($con){
echo "$con";
}
function writeBold($con){
echo "$con";
}
$myFupnction="write";
$myFupnction("这是动态调用函数不加粗的例子!");
$myFupnction="writeBold";
$myFupnction("这是动态调用加粗的例子!")
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn