For those who are not familiar with this concept, the loop is a control structure that allows you to reuse the same series of PHP commands over and over again. The number of actual repetitions can be determined by yourself.
The first, and simplest, loop is the so-called "while" loop, as follows:
while (condition)
{
Do this!
}
Or, in Chinese.
while (it rained)
{
Take your umbrella!
}
In this case, as long as the value of the condition is true, remember how you learned it last time?---the PHP command in the braces will be executed. As long as the condition becomes false-for example, in the example above, the sun comes out, the loop terminates, and the subsequent commands are no longer executed.
Here is a simple example of how to use the "while" Loop:
<?
If the form has not yet been submitted, the initialization page is displayed
if (! $submit)
{
?>
< html>
< head>
< body>
< h2> incredible time machine for other people------< form action= "tmachine.php" method= "POST" >
Which year would you like to visit?
< input type= "text" name= "Year" size= "4" maxlength= "4" >
< input type= "submit" name= "Submit" value= "Go" >
</form>
</body>
<?
}
Else
Otherwise, it is processed and a new page is generated
{
?>
< html>
< head>
< body>
<?
The current year
$current = 2001;
Check for future time and generate the appropriate information
In this example, we first ask the user the year he wants to visit-the year is stored in the variable, and transferred to the PHP script.
The script first checks the year to confirm that it was in the past [hehe, we're doing these things ourselves now] and then using a "while" loop to calculate backward from the current year-2001 to have the result in the variable present until the values of $current and $year are the same.
Note that we make the same PHP page generate both the initialization form and the processing page by using the submit variable-this technique we've explained to you in detail last time.
http://www.bkjia.com/PHPjc/315766.html www.bkjia.com true http://www.bkjia.com/PHPjc/315766.html techarticle for those who are not familiar with this concept, the loop is a control structure that allows you to reuse the same series of PHP commands over and over again. The number of actual repetitions can be determined by yourself. ...