Home > Backend Development > PHP Tutorial > Basic applications of PHP functions

Basic applications of PHP functions

高洛峰
Release: 2023-03-01 12:38:01
Original
1246 people have browsed it

The code is as follows:

<?php 
/* 
* 简单的函数 
*/ 
function fontBold($con){ 
return "<B>$con</B>"; 
} 
$str="简单的函数测试!"; 
echo "普通文本:$str<br>"; 
echo "加粗文本:".fontBold($str).""; 
/* 
* 带可选参数的函数 
*/ 
function fontColor($con,$color="bule"){ 
return "<font color=\"$color\">$con</font>"; 
} 
$str="颜色测试"; 
echo $str; 
echo fontColor($str."这是不带颜色参数的(默认为蓝色)!"); 
echo fontColor($str,"red"."这是带颜色参数的(默认为红色!)"); 
/* 
* 递归函数 
*/ 
function chckint($Num){ 
if($Num>1){ 
return chckint($Num-1); 
}else if($Num<0){ 
return chckint(($Num*-1)-1); 
}else{ 
if($Num>0 && $Num<1){ 
return 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 "<b>$con</b>"; 
} 
$myFupnction="write"; 
$myFupnction("这是动态调用函数不加粗的例子!"); 
$myFupnction="writeBold"; 
$myFupnction("这是动态调用加粗的例子!") 
?>
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template