如果是真的PHP,如何处理所有情况 [英] How to proceed through all cases if they are true PHP

查看:90
本文介绍了如果是真的PHP,如何处理所有情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以处理所有这三种情况,如果它们都为真,但是以break为例,因为,第一种情况为true,第二种情况为false,第三种情况为假也是错误的,并且我没有使用break,无论如何它都会处理低谷.更改strtotime为2014年10月6日,您会明白我的意思

I want to know if there is a way to proceed through all three cases,if they are all true,but with using break,because as an example,if the first case is true,the second case is false and the third is also false,and i am not using break,it will procced trough all anyway.Change the strtotime with 6 October 2014,and you will see what i mean

$date = strtotime("1 October 2014"); 
switch($date) {  
     case (date('l', $date) == 'Monday'): //case 1: If the current day is Monday
      echo "weekly<br>";
     break;

     case (date('d', $date) == '01'):  //case 2: If the current day of the month is 1
      echo "monthly<br>";                       
     break;

    case ( ((date('n') % 3) == '1') && (date('d') == '01') ): //case 3: If a quart of the year has just passed,and we are in the first day of a new quart
      echo 'quarterly<br>';     
    break;   

}

任何建议???如果无法使用switch,我应该如何使用它来执行代码行3次,每种情况一次.

Any suggestion??? And if it is not possible with switch,how should i make it with if,to execute the code line 3 times,one for each case.

推荐答案

尝试

$date = strtotime("1 October 2014"); 

     if (date('l', $date) == 'Monday'){ //case 1: If the current day is Monday
      echo "weekly<br>";
     }
     if (date('d', $date) == '01'){  //case 2: If the current day of the month is 1
      echo "monthly<br>";                       
     }
    if ( ((date('n', $date) % 3) == '1') && (date('d', $date) == '01') ){ //case 3: If a quart of the year has just passed,and we are in the first day of a new quart
      echo 'quarterly<br>';   
    }  

这篇关于如果是真的PHP,如何处理所有情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆