Classic Loop examples
Classic Loop examples
for ($counter = 1; $counter <= 6; $counter + +)//cycle 6 times
{
Print ("counter is $counter
"); Print 6 times
}
?>
For advanced use
For advanced use
/*
* * Print the necessary explanatory text
*/
Print (" How many days away from Monday?") ");
Print ("
");
for ($currentDate = Date ("U");//define $currentdate time format
Date ("L", $currentDate)! = "Monday"; Determine if the current system time is Monday
$currentDate + = (60 * 60 * 24))//Current time plus 1 days
{
/*
* * Print time name
*/
Print ("
- " . Date ("L", $currentDate). "");
}Print ("
");
?>
Simple invocation of the function:
simple functions
!--? function Printbold ($inputText)//define function Printbold ()
{
Print (" ". $inputText. ""); Printing $inputtext
}
Print ("This line is not aggravating!")
"); Direct Print string
Printbold ("This line is aggravating!!! "); Call function Printbold ()
Print ("
");
Print ("This line is not aggravating!")
"); Direct print string
?
function with return value
function with return value
!--? function Makebold ($inputText)//define function Makebold () functions
{
$boldedText = " ";
$boldedText. = $inputText;
$boldedText. = "";
return ($boldedText);//return variable $boldedtext
}
Print ("This line is not aggravating!!!")
"); Print the string directly
print (Makebold ("This line is aggravated!!! ") . "
");//Call Function Makebold () function
Print (" This line is not aggravating!!! ")
"); Direct print string
?
Functions with default parameters
Functions with default parameters
function printcolored ($Text, $Color = "BLACK")//define function functions
{
Print ("$Text"); Get the contents and colors of a string
}
Printcolored ("This is the black color of the word!") "); Calling function functions
Print ("
");
Printcolored ("This is the blue color of the word!") "," Blue "); Calling function functions
Print ("
");
?>
Determines whether an integer is
judging integers
!--? 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, */
/* Can parse its absolute value */
Return (Checkinteger (( -1) * $Number-1));//Take absolute value, Parse negative numbers by integer
}
Else
{
if (($Number > 0) and ($Number < 1))
{
Return ("Of course not");
}
Else
{
/* 0 and 1 are integers */
/* Based on relevant mathematical definitions */
Return ("yes");
}
}
}
Print (" 0 is an integer? " .
Checkinteger (0). "
");
Print (" 7 is an integer?) " .
Checkinteger (7). "
");
Print (" 3.5?"). " . Checkinteger (3.5). "
");
Print (" so-5? " . Checkinteger (-5). "
");
Print (" and-9.2? " . Checkinteger (-9.2). "
");
?
Initialize array
Initializing an array
$monthName = Array (1=> "January", "February", "March",//initialization of an array
"April", "may", "June", "July", "August",
"September", "October", "November", "D
http://www.bkjia.com/PHPjc/486620.html www.bkjia.com true http://www.bkjia.com/PHPjc/486620.html techarticle Classic Loop Example HTML HEAD TITLE Classic Loop Example/title/head BODY for ($counter = 1; $counter = 6; $counter + +)//loop 6 times {print ("Bcounter I s $counter/bbr "); Print 6 times} ...