经典循环例子
经典循环例子
for($counter = 1; $counter <= 6; $counter++) //循环6次
{
print("counter is $counter
"); //打印6次
}
?>
for的高级运用
for的高级运用 /*
** 打印必要的说明文字
*/
print("
距离星期一还有几天?
");
print("
");
for($currentDate = date("U"); //定义$currentDate时间格式
date("l", $currentDate) != "Monday"; //判断是不是当前系统时间是Monday
$currentDate += (60 * 60 * 24)) //当前时间加上1天
{
/*
** 打印时间名称
*/
print("- " . date("l", $currentDate) . "
");
}
print("
");
?>
函数的简单调用:
简单的函数
function printBold($inputText) //定义function printBold()
{
print("" . $inputText . ""); ////打印$inputText
}
print("这行没有加重!
"); //直接打印字符串
printBold("这行加重了!!!"); //调用function printBold()函数
print("
");
print("这行没有加重!
"); //直接打印字符串
?>
有返回值的函数
有返回值的函数
function makeBold($inputText) //定义function makeBold()函数
{
$boldedText = "";
$boldedText .= $inputText;
$boldedText .= "";
return($boldedText); //返回变量$boldedText
}
print("这行没有加重!!!
"); //直接打印字符串
print(makeBold("这行被加重了!!!") . "
");//调用function makeBold()函数
print("这行没有加重!!!
"); //直接打印字符串
?>
Function with default parameters
Function with default parameters
function printColored($Text, $Color="black") //Define function function
{
print( "$Text"); //Get the content and color of the string
}
printColored("This is a black word!"); //Call function
print("
");
printColored("This is a blue word!", "blue"); //Call function
print("
");
?>
Use the rule algorithm to determine whether it is an integer
Judge integer
function checkInteger($Number)
{
if($Number > 1)
{
/* An integer minus 1 is still an integer*/
return(checkInteger($ Number- 1));
}
elseif($Number < 0)
{
return(checkInteger((-1)*$Number-1));//Take the absolute value and analyze negative numbers as integers
) AND ($Number < 1))
/* 0 and 1 are integers 🎜> ; Is 0 an integer? < /B>" .
checkInteger(0)
");
print("Is 7 an integer? " .
checkInteger(7) . "
");
print("What about 3.5?" . checkInteger(3.5) . "
");
print("What about -5?" . checkInteger(-5) . "
");
print("And -9.2?" . checkInteger(-9.2) . "
");
?>
Initialization array
Initialization array
< ;?
$monthName = array(1=>"January", "February", "March",//Initialize an array
"April", "May", "June", "July", "August",
"September", "October", "November", "D
http://www.bkjia.com/PHPjc/486620.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486620.htmlTechArticleClassic loop example HTML HEAD TITLE Classic loop example/TITLE /HEAD BODY ? for($counter = 1; $counter = 6; $counter++) //Loop 6 times { print("Bcounter is $counter/BBR"); //Print 6 times}...