Classic loop example HTMLHEADTITLE classic loop example/TITLE/HEADBODY? For ($ counter = 1; $ counter = 6; $ counter ++) // Loop 6 Times {print (Bcounteris $ counter/BBR \ n ); // Print 6 times }? /BODY/HTMLf
Classic loop example
Classic loop example
For ($ counter = 1; $ counter <= 6; $ counter ++) // 6 cycles
{
Print ("Counter is $ counter
\ N "); // Print 6 times
}
?>
Advanced application of
Advanced application of
/*
** Print necessary instructions
*/
Print ("How many days are there from Monday?\ N ");
Print ("
\ N ");
For ($ currentDate = date ("U"); // defines the $ currentDate time format
Date ("l", $ currentDate )! = "Monday"; // determines whether the current system time is Monday.
$ CurrentDate + = (60*60*24) // add 1 day to the current time
{
/*
** Print the time name
*/
Print ("
- ". Date (" l ", $ currentDate)." \ n ");
}Print ("
\ N ");
?>
Simple function call:
Simple functions
Function printBold ($ inputText) // defines the function printBold ()
{
Print ("". $ InputText .""); // Print $ inputText
}
Print ("This line is not aggravated!
\ N "); // Print the string directly
PrintBold ("This line is aggravated !!! "); // Call the function printBold () function
Print ("
\ N ");
Print ("This line is not aggravated!
\ N "); // Print the string directly
?>
Functions with return values
Functions with return values
Function makeBold ($ inputText) // defines the function makeBold () function
{
$ BoldedText ="";
$ BoldedText. = $ inputText;
$ BoldedText. ="";
Return ($ boldedText); // return the variable $ boldedText
}
Print ("This line is not aggravated !!!
\ N "); // Print the string directly
Print (makeBold ("This line is aggravated !!! ")."
\ N "); // call the function makeBold () function
Print ("This line is not aggravated !!!
\ N "); // Print the string directly
?>
Functions with default parameters
Functions with default parameters
Function printColored ($ Text, $ Color = "black") // defines the function.
{
Print ("$ Text"); // Obtain the content and color of the string.
}
PrintColored ("This is a black color word! "); // Call the function
Print ("
\ N ");
PrintColored ("This is a blue color word! "," Blue "); // call the function
Print ("
\ N ");
?>
Use a regular algorithm to determine whether it is an integer
Judge integer
Function checkInteger ($ Number)
{
If ($ Number> 1)
{
/* The integer minus 1 is still an integer */
Return (checkInteger ($ Number-1 ));
}
Elseif ($ Number <0)
{
/* For a negative number ,*/
/* You can analyze its absolute value */
Return (checkInteger (-1) * $ Number-1); // Obtain the absolute value and analyze the negative Number by an integer.
}
Else
{
If ($ Number> 0) AND ($ Number <1 ))
{
Return ("Of course not ");
}
Else
{
/* 0 and 1 are integers */
/* According to the mathematical definition */
Return ("yes ");
}
}
}
Print ("Is 0 an integer?".
CheckInteger (0 )."
\ N ");
Print ("Is 7 an integer?".
CheckInteger (7 )."
\ N ");
Print ("What about 3.5?". CheckInteger (3.5 )."
\ N ");
Print ("What about-5?". CheckInteger (-5 )."
\ N ");
Print ("And-9.2?". CheckInteger (-9.2 )."
\ N ");
?>