Practical Application Experience of PHP4 (5)

Source: Internet
Author: User

Author: Sun sports

PHP also provides you with a way to handle multiple possibilities-the "if-elseif-else" structure. A typical "if-elseif-else" structure statement is as follows:

--------------------------------------------------------------------------------
If (the first condition is correct)
{

Do this!
}
Elseif (the second condition is correct)
{

Do this!
}
Elseif (the third condition is correct)
{

Do this!
}
... And so on...
Else
{

Do this!
}
--------------------------------------------------------------------------------
Here is an example of how to use it:

--------------------------------------------------------------------------------
<Html>
<Head>
<Style type = "text/css">
Td {font-family: Arial ;}
</Style>
</Head>

<Body>

<Font face = "Arial" size = "+ 2">
Amazing lucky cookie production program
</Font>

<Form method = "GET" action = "cookie. php">
<Table cellspacing = "5" cellpadding = "5" border = "0">

<Tr>
<Td align = "center">
Select a date
</Td>
<Td align = "right">
<Select name = "day">
<Option value = "Monday"> Monday
<Option value = "Tuesday"> Tuesday
<Option value = "Wednesday"> Wednesday
<Option value = "Thursday"> Thursday
<Option value = "Friday"> Friday
<Option value = "Saturday"> Saturday
<Option value = "Sunday"> Sunday
</Select>
</Td>
</Tr>

<Tr>
<Tr>
<Td colspan = "2" align = "center">
<Input type = "submit" value = "Click me! ">
</Td>
</Tr>

</Table>
</Form>
</Body>

</Html>
--------------------------------------------------------------------------------
As you will see, this simple form allows you to select a day of the week. The actual processing work is done by the submitted PHP script "cookie. php.

--------------------------------------------------------------------------------
<?

If ($ day = "Monday ")
{
$ Fortune = "do not make everything simple and effective when you can find a complicated and wonderful way to do everything .";
}
Elseif ($ day = "Tuesday ")
{
$ Fortune = "is life a bridge to games? -You must use some clever tricks. ";
}
Elseif ($ day = "Wednesday ")
{
$ Fortune = "What makes people with clear minds never go crazy in this world? ";
}
Elseif ($ day = "Thursday ")
{
$ Fortune = "don't be crazy, be fun ";
}
Elseif ($ day = "Friday ")
{
$ Fortune = "just follow the times and follow the ethos. When you get an improvement, you will find that the type is a devil. ";
}
Else
{
$ Fortune = "sorry, the weekend is closed ";
}

?>

<Html>
<Head>
<Basefont face = "Arial">
</Head>

<Body>
This is you <? Echo $ day;?> Lucky words:
<Br>
<B> <? Echo $ fortune;?> </B>

</Body>
</Html>
--------------------------------------------------------------------------------
In this case, we use a control sentence to assign different Lucky words to each day.

Here is an important point worth noting-when a "if" statement in the structure is found to be true, PHP will execute the corresponding code, ignore the "if" statement in the remaining structure, immediately jump out of the "if-elseif-else" structure, and execute the rows following the entire structure.

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.