Author: Sun Sports
Another type of "if-else" family control statement function is almost the same as the PHP "switch" statement. It looks as follows:
--------------------------------------------------------------------------------
Switch (decision variable)
{
The first condition of case is correct:
Do this!
The second condition of case is correct:
Do this!
The third condition of case is correct:
Do this!
... Wait a minute...
}
--------------------------------------------------------------------------------
We will use the "switch" statement to rewrite the above example of the lucky cookie to make these notes clearer:
[cookie.php]
--------------------------------------------------------------------------------
<?
The decision variable here is the date selected by the user
Switch ($day)
{
First case
Case "Monday":
$fortune = "Do not make it simple and effective when you can find a complex and wonderful way to make everything happen";
Break
The second case
Case "Tuesday":
$fortune = "Life is the bridge of the game?"-you must have some kind of inventions. ";
Break
The third case
Case "Wednesday":
$fortune = "What makes a sane person live in this world and never go mad?" ";
Break
Fourth case
Case "Thursday":
$fortune = "Don't be crazy, be funny";
Break
Fourth case
Case "Friday":
$fortune = "Just follow the times, along the lines of the atmosphere, and when you get promoted you will find that the type is a demon." ";
Break
If none of the above conditions are met ...
Default
$fortune = "Sorry, the weekend is closed";
Break
}
?>
< html>
< head>
< Basefont face= "Arial" >
< body>
Is this your <? Echo $day;?> 's lucky words:
< br>
< b><? echo $fortune;?></b>
</body>
--------------------------------------------------------------------------------
There are two important keywords: the keyword "break" is used to interrupt the "switch" statement structure and immediately moves out of the structure block, and then runs the row immediately following the block. The "default" keyword is used to execute statements that are set when a variable passed to "switch" does not conform to any of the cases enumerated in the statement structure.
The above describes the premiere pro cs4 download PHP4 practical application Experience 7, including the premiere pro cs4 download content, want to be interested in PHP tutorial friends helpful.