php - 如果它们是真实的,如何处理所有情况 PHP

标签 php switch-statement case

我想知道是否有办法处理所有三种情况,如果它们都是真的,但是使用 break,因为举个例子,如果第一种情况为真,第二种情况为假,第三种情况也是错误的,我没有使用 break,无论如何它都会发生。将 strtotime 更改为 2014 年 10 月 6 日,您就会明白我的意思

$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,我应该如何使用 if 来执行代码行 3 次,每种情况一次。

最佳答案

这不是 switch 的工作方式 - 它旨在根据定义的条件执行单行执行 - 因此是“开关”。用单独的 if 语句替换它。

关于php - 如果它们是真实的,如何处理所有情况 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25682432/

相关文章:

SQL服务器: Check if variable is null and then assign statement for Where Clause

php - 将列表中的数据插入 mysql 数据库

php - 删除除特定文本和值正则表达式之外的所有文本

php - 使用 PHP 将数据从 csv 添加到 mysql 时出现问题

php - 创建一个查找函数来获取字符之间的字符串

mysql - SQL更新案例中需要if/else语句

java - 带字符串的 switch 不仅仅是语法糖吗?

java - String 是关于 switch 的数字类型并且总是编译为 lookupswitch 吗?

vb.net - 在 VB.NET 中选择对象类型的大小写

sql-server - 在 CASE 表达式中使用 tsql 大于号