国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

switch statement

PHP Switch Statement

If you want to selectively execute one of several blocks of code, use the switch statement.

Syntax

switch (n)
{
case label1:
         如果 n=label1,此處代碼將執(zhí)行;
         break;
case label2:
         如果 n=label2,此處代碼將執(zhí)行;
         break;
default:
         如果 n 既不等于 label1 也不等于 label2,此處代碼將執(zhí)行;
}

Working principle: First perform a calculation on a simple expression n (usually a variable). Compares the value of the expression to the value of each case in the structure. If there is a match, the code associated with the case is executed. After the code is executed, use break to prevent the code from jumping to the next case to continue execution. The default statement is used to execute when there is no match (that is, no case is true).

Example

<?php
 $favcolor="red";
 switch ($favcolor)
 {
 case "red":
     echo "你喜歡的顏色是紅色!";
     break;
 case "blue":
     echo "你喜歡的顏色是藍(lán)色!";
     break;
 case "green":
     echo "你喜歡的顏色是綠色!";
     break;
 default:
     echo "你喜歡的顏色不是 紅, 藍(lán), 或綠色!";
 }
 ?>

Multi-way branch structure

1. In switch() brackets, it must be a variable

2.In switch(){} The most common ones in China are case statements, case spaces, followed by values, and a colon after the value:

switch(變量){
                   case 值:
                                     語(yǔ)句;
                                     語(yǔ)句;
                                     語(yǔ)句;
                               語(yǔ)句;
                                     break;
                   case 值2:
                                     語(yǔ)句;
                                     break;
                   case 值3:
                                     語(yǔ)句;
                                     break;
                   .......
}

switch-case Some details to pay attention to:

1. If in If there are too many statements in the case, you need to make multiple statements into a function or the like

2switch (variable) variable type, the value allows two types: integer and string.

3.break is used to exit the switch structure. If you need to match multiple values ??at the same time, you can use multiple cases without adding break.

Continuing Learning
||
<?php $favcolor="red"; switch ($favcolor) { case "red": echo "你喜歡的顏色是紅色!"; break; case "blue": echo "你喜歡的顏色是藍(lán)色!"; break; case "green": echo "你喜歡的顏色是綠色!"; break; default: echo "你喜歡的顏色不是 紅, 藍(lán), 或綠色!"; } ?>
submitReset Code