In-depth understanding of php4 -- going back to the future

Source: Internet
Author: User
For those who are not familiar with this concept, loop is a control structure that allows you to repeatedly use the same series of php commands. The actual number of repetitions can be determined by yourself. The first and simplest cycle is the so-called & quot; while & quot; loop, as shown below: while (condition) {dothis !} Or use Chinese to represent while (rain) {for those who are not familiar with this concept, loop is a control structure that allows you to repeat the same 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 "while" loop, as shown below:

While (condition)
{
Do this!
}

Or, in Chinese

While (rain)
{
Bring an umbrella!
}

In this case, as long as the value of the condition is true, do you still remember how to learn it last time? --- The PHP commands in the large arc will be executed all the time. As long as the condition changes to a false value-for example, in the above example, when the sun comes out, the loop ends and the subsequent commands will not be executed.

Here is a simple example to illustrate how to use the "while" loop:



<?

// If the form has not been submitted, the initialization page is displayed.
If (! $ Submit)
{
?>

<Html>

<Head>
</Head>

<Body>
<H2> another incredible time machine
<Form action = "tmachine. php" method = "POST">
Which year are you planning to visit?
<Input type = "text" name = "year" size = "4" maxlength = "4">
<Input type = "submit" name = "submit" value = "Go">
</Form>
</Body>
</Html>

<?
}
Else
// Otherwise, it will be processed and a new page will be generated
{
?>

<Html>

<Head>
</Head>

<Body>

<?
// Current year
$ Current = 2001;

// Check the future time and generate relevant information


In this example, we first ask the user about the year he wants to access-the year which is stored in the variable year and transmitted to the PHP script.

The script first checks the year to confirm that it was in the past [haha, now we seem to be doing these things by ourselves] then we use a "while" loop to calculate the result from the current year-2001 backward and store the result in the current variable, until the values of $ current and $ year are the same.

Please note that we use the submit variable to make the same PHP page generate both an initialization form and a processing page-this technology has been described in detail last time.

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.