PHP switch case more than one value in the case

前端 未结 3 639
南旧
南旧 2020-12-02 18:10

I have a variable that holds the values \'Weekly\', \'Monthly\', \'Quarterly\', and \'Annual\', and I have another variable that holds the values from 1 to 10.



        
3条回答
  •  忘掉有多难
    2020-12-02 18:33

    switch ($var2) {
           case 1 :
           case 2 :
              $var3 = 'Weekly';
              break;
           case 3 :
              $var3 = 'Monthly';
              break;
           case 4 :
           case 5 :
              $var3 = 'Quarterly';
              break;
    }
    

    Everything after the first matching case will be executed until a break statement is found. So it just falls through to the next case, which allows you to "group" cases.

提交回复
热议问题