Explore PHP4 (1)--back to the future _php tutorial

Source: Internet
Author: User
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. ...

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.