For those of you who are unfamiliar with this concept, loops are a control structure that allows you to reuse a series of PHP commands over and over again. The actual number of 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 the Umbrella!
}
In this case, as long as the value of the condition is true, remember how the last time you learned it?---the PHP command in brackets will always execute. 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:
<?
Displays the initialization page if the form has not yet been submitted
if (! $submit)
{
?>
< html>
< head>
< body>
< h2> incredibly wonderful Time Machine (Times machine) < 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 the future time and generate the appropriate information
In this example, we first ask the user about the year that he wants to visit-the year is stored in the yearly variable and sent to the PHP script.
The script first checks the year to confirm that it was in the past [hehe, we're doing these things now.] Then use a "while" loop to calculate the result from the current year-2001 backwards, until the values of $current and $year are the same.
Note that we have used the submit variable to make the same PHP page produce both the initialization form and the processing page-the technique we have explained to you last time.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.