php 补全日期查询中缺少的日期

<?php

$data = ['2017-08-24',
        '2017-08-26',
        '2017-08-28',
        '2017-08-30',
        '2017-08-31'];
$len = count($data);
$oneDaySecond = 86400;
$newData = array();
for ($i = 1; $i < $len; $i++) {
    $previous = strtotime(str_replace('.', '-', $data[($i - 1)]));
    $current = strtotime(str_replace('.', '-', $data[($i)]));
    $diff = $current - $previous;
    if (!in_array($data[($i - 1)], $newData, true)) {
        $newData[] = $data[($i - 1)];
    }
    if ($diff > $oneDaySecond) {
        for ($m = $previous + $oneDaySecond; $m < $current; $m += $oneDaySecond) {
            $newData[] = date('Y-m-d', $m);
        }
    }
    $newData[] = $data[$i];
}
print_r($newData);

上一篇:js数组转换


下一篇:轮播一页显示多少条数据