gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 22:54:26 24 4
gpt4 key购买 nike

我想知道是否有办法处理所有三种情况,如果它们都是真的,但是使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com