Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 每月重置内容_Php - Fatal编程技术网

Php 每月重置内容

Php 每月重置内容,php,Php,我现在有一个每周六重置的代码,它的内容将显示整个星期,直到下周六。我希望每月使用相同的方法(显示整个月的内容,直到下一个月的新内容),但我无法让它工作。每周代码如下: $dayoftheweek = date("l"); $todayis = date('Y-m-d'); if($dayoftheweek == 'Saturday') { // The day it updates $dateUpdate = $todayis; } else { $dateUpdate

我现在有一个每周六重置的代码,它的内容将显示整个星期,直到下周六。我希望每月使用相同的方法(显示整个月的内容,直到下一个月的新内容),但我无法让它工作。每周代码如下:

$dayoftheweek = date("l");
$todayis = date('Y-m-d');

if($dayoftheweek == 'Saturday') { // The day it updates
    $dateUpdate = $todayis; 
} else {  
    $dateUpdate = date("Y-m-d", strtotime( "$todayis last Saturday" )); // The day it updates
}

// Content to display
switch($dateUpdate) {
    case '2020-05-02':
        // Content here
    break;
    case '2020-05-09':
        // Content here
    break;
    default:
        // Display content when ran out of rounds
}
我每月都在遵循相同的代码模式,我是不是在做错事?这是我现在掌握的每月代码:

$firstofmonth = date("d");
$thisday = date('Y-m-d');

if($firstofmonth == '01') {
    $MonthlyUpdate = $thisday;
} else {
    $MonthlyUpdate = date("Y-m-d", strtotime("first day of -1 month"));
}
当我将案例日期设置为“2020-05-01”时,我每月应该拥有的内容没有与上面的代码一起显示。再说一次,我是不是做错了什么?还是有更好的方法?非常感谢

去掉日期(
d
)变量,只检查月份+年份:

switch(date('Y-m')) {
    case '2020-05':
        // Content here
    break;
    case '2020-06':
        // Content here
    break;
    default:
        // Display content when ran out of rounds
}

这似乎是一个非常奇怪的方法。这应该通过使用数据库来完成。为什么?数据库用于表格数据结构。为什么?数据库用于表格数据结构。。。。没错,你已经回答了自己的问题@dehartI不明白,为什么要建立数据库?OP讨论了基于日期的行为@B001ᛦ要显示的内容应存储在链接到相应日期的数据库中,除非您不想每天/每周/每月/每年修改代码。编写代码不仅要理解正确的语法,还要理解@dehart的可伸缩性和可维护性