凤凰求蛊
<?php
$data = array(
'date' => array(
'2017.08.24',
'2017.08.26',
'2017.08.28',
'2017.08.30',
'2017.08.31'
),
'data' => array(
1,
2,
3,
4,
5
)
);
$len = count($data['date']);
$oneDaySecond = 86400;
$newData = array();
for ($i = 1; $i < $len; $i++) {
$previous = strtotime(str_replace('.', '-', $data['date'][($i - 1)]));
$current = strtotime(str_replace('.', '-', $data['date'][($i)]));
$diff = $current - $previous;
if (!in_array($data['date'][($i - 1)], $newData['date'], true)) {
$newData['date'][] = $data['date'][($i - 1)];
$newData['data'][] = $data['data'][($i - 1)];
}
if ($diff > $oneDaySecond) {
for ($m = $previous + $oneDaySecond; $m < $current; $m += $oneDaySecond) {
$newData['date'][] = date('Y.m.d', $m);
$newData['data'][] = 0;
}
}
$newData['date'][] = $data['date'][$i];
$newData['data'][] = $data['data'][$i];
}
print_r($newData);
result
Array
(
[date] => Array
(
[0] => 2017.08.24
[1] => 2017.08.25
[2] => 2017.08.26
[3] => 2017.08.27
[4] => 2017.08.28
[5] => 2017.08.29
[6] => 2017.08.30
[7] => 2017.08.31
)
[data] => Array
(
[0] => 1
[1] => 0
[2] => 2
[3] => 0
[4] => 3
[5] => 0
[6] => 4
[7] => 5
)
)