Classic loop example
Classic loop example for($counter = 1; $ counter <= 6; $counter++) //Loop 6 times
} {
;BODY>
. n");
for($currentDate = date("U"); //Define the $currentDate time format
date("l", $currentDate) != "Monday"; //Judge whether it is current The system time is Monday. print("- " . date ("l", $currentDate) . "n");
}
print("
n");
?>
Simple call of function :
Simple function
<
function printBold ($inputText) //Define function printBold()
{
"This business No aggravation!
n"); . ("This line is not emphasized!
n"); //Print the string directly
?>
Function with return value
Function with return value
function makeBold ($inputText) //Define the function makeBold() function
>";
return($ boldedText); //Return variable $boldedText
}
print("This line is not bold!!!
n"); //Print the string directly
print(makeBold("This line is bold!!! ")." & Lt; br & gt; n "); // Call the function makebold () function
Print (" This line is not worse!!!!
n"); //Print the string directly
?>
Function with default parameters
< HEAD>
"black") . This is the word of black color! "); // call the function function
Print (" & lt; br & gt; & lt; br & gt;"," Blue "); // Call the function function
Print (" & lt; br & gt; n "); Algorithm to determine whether it is an integer
Judge integer
Function checkInteger($Number)
{
elseif($Number * For a negative number, */
/* You can analyze its absolute value*/
}
* According to relevant mathematical definitions */
" ;BR>n");
print("7 is an integer? " .
checkInteger(7) . "
n");
print(" What about 3.5? " . checkInteger(3.5) . "
n");
print("What about -5?" . checkInteger(-5) . "< BR>n");
print("And -9.2?" . checkInteger(-9.2) . "
n");
?>
Initialize array
Initialize array
& lt;? " September", "October", "November", "December");
print(""May" in English is $monthName[5] .
n");//Print the 6th element in the array
?>
Get the element in the array
Get elements in the array
$monthName = array(
) /*Define $monthName[1] to $monthName[ 12]*/
1=>"January", "February", "March",
"April", "May", "June",
"July", "August", "September",
" October ", "November", "December",
/*Define $monthName["Jan"] to $monthName["Dec"]*/
"Jan"=>"January", "Feb"=>"February ",
"Mar"=>"March", "Apr"=>"April",
"May"=>"May", "Jun"=>"June",
"Jul"=> ;"July", "Aug"=>"August",
"Sep"=>"September", "Oct"=>"October",
"Nov"=>"November", "Dec" =>"December",
" /*Define $monthName["Jan"] to $monthName["Dec"]*/
"January"=>"January", "February"=>"February",
"March"=>"March", "April"=>"April",
"May"=>"May", "June"=>"June",
"July"=>"July ", "August"=>"August",
"September"=>"September", "October"=>"October",
"November"=>"November", "December"=> "December"
);
/*Print related elements*/
print("Month 5 is " . $monthName[5]. "< BR>n");
print("Month Aug is " . $monthName["Aug"] . "
n");
print("Month June is " . $monthName["June"] . "
n");
?>
BODY>
Create a multidimensional array
Create a multidimensional array
$Cities =array( // Two-dimensional array array ()
"North China" =>array(
"Xi'an",
"Lhasa"
" Northern Region"][0]
?>