PHP头条
热点:

php获取最近n天组成数组


php获取某个时间点之前的前 n 天,将结果组成数组。

/**
 * 获取某个时间点之前的前 n 天
 * @param int $recent
 * @param int $time
 * @return array
 */
function getRecentDays($recent = 6, $time = 0) {
    !$time && $time = time();

    $list = [];

    for ($i = $recent; $i > 0; --$i) {
        $t = strtotime("-$i day", $time);
        $list[] = date('Y-m-d', $t);
    }

    return $list;
}
print_r(getRecentDays(2, strtotime('2019-03-01')));

输出:

Array
(
    [0] => 2019-02-27
    [1] => 2019-02-28
)

www.phpzy.comtrue/php/24333.htmlTechArticlephp获取最近n天组成数组 php获取某个时间点之前的前 n 天,将结果组成数组。 /** * 获取某个时间点之前的前 n 天 * @param int $recent * @param int $time * @return array */function getRecentDays($recent = 6...

相关文章

PHP之友评论

今天推荐