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);
标签:补全,oneDaySecond,current,日期,print,php,newData 来源: https://www.cnblogs.com/yaoliuyang/p/15209839.html