<?php
$dates = [
'2021-07-05',
'2021-07-06',
'2021-07-07',
'2021-07-08',
'2021-07-09',
'2021-07-10',
'2021-07-11',
'2021-07-12',
'2021-07-13',
'2021-07-14',
'2021-07-15',
'2021-07-16',
'2021-07-17',
'2021-07-18',
'2021-07-19',
'2021-07-20',
'2021-07-21',
'2021-07-22',
];
$from = $dates[0];
$to = $from;
$result = [];
foreach($dates as $date) {
if (strtotime($from) + 60 * 60 * 24 * 6 < strtotime($date)) {
$result[] = ['from' => $from, 'to' => $to];
$from = $to;
}
$to = $date;
}
$result[] = ['from' => $from, 'to' => $to];
print_r($result);
preferences:
50.02 ms | 402 KiB | 5 Q