PHP also provides you with a "IF-ELSEIF-ELSE" structure that handles a variety of possible ways. A typical "IF-ELSEIF-ELSE" structure statement looks like this:
--------------------------------------------------------------------------------
if (the first condition is correct)
{
Do this!
}
ElseIf (second correct condition)
{
Do this!
}
ElseIf (third condition correct)
{
Do this!
}
... Wait a minute...
Else
{
Do this!
}
--------------------------------------------------------------------------------
Here is an example of how to use this:
--------------------------------------------------------------------------------
You will see that this simple form allows you to choose a day of the week. The real processing work is done by submitting the PHP script "cookie.php".
if ($day = = "Monday")
{
$fortune = "Do not make it simple and effective when you can find a complex and wonderful way to make everything work."
}
ElseIf ($day = = "Tuesday")
{
$fortune = "Life is the bridge of the game?"-you must have some kind of cunning. ";
}
ElseIf ($day = = "Wednesday")
{
$fortune = "What makes the sane person live in this world and never go mad?" ";
}
ElseIf ($day = = "Thursday")
{
$fortune = "Do not be crazy, be interesting";
}
ElseIf ($day = = "Friday")
{
$fortune = "Just follow the times, follow the ethos, and when you get promoted you will find that the type is a demon." ";
}
Else
{
$fortune = "Sorry, closed on weekends";
}
?>
< html>
< head>
< Basefont face= "Arial" >
< body>
Is this you <? Echo $day;?> 's lucky words:
< br>
< b><? echo $fortune;?></b>
</body>
--------------------------------------------------------------------------------
In this case, we use control sentences to assign different lucky words to each day.
One important point to note here-when an "if" statement in a struct is found to be true, PHP executes the code, ignores the "if" statement in the remaining structure, and immediately jumps out of the "IF-ELSEIF-ELSE" structure and executes the line behind the entire structure.
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