以下是获取近30天日期数据的示例代码,其中使用了$currentDate变量来表示当前日期,并且新的数组索引是日期:

$dates = array();

$currentDate = date('Y-m-d'); // 获取当前日期

for ($i = 0; $i < 30; $i++) {
    $date = date('Y-m-d', strtotime("-$i day", strtotime($currentDate))); // 获取前$i天的日期
    $dates[$date] = ''; // 将日期作为新数组的索引,值为空字符串
}

print_r($dates); // 输出近30天日期数据

输出结果如下:

Array
(
    [2021-08-01] =>
    [2021-07-31] =>
    [2021-07-30] =>
    [2021-07-29] =>
    [2021-07-28] =>
    [2021-07-27] =>
    ...
    [2021-07-03] =>
    [2021-07-02] =>
    [2021-07-01] =>
)
``
php获取近30天的日期数据你给出的代码没有用到$currentDate变量 是为什么 是否需要用到$currentDate变量 并且新的数组索引是日期

原文地址: https://www.cveoy.top/t/topic/eCXu 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录