Если предположить, что дни недели упорядочены по возрастанию, то можно использовать что-нибудь такое:
$openingHours = [
['day' => 'monday', 'time' => '08:00-20:00'],
['day' => 'tuesday', 'time' => '08:00-20:00'],
['day' => 'wednesday', 'time' => '08:00-23:59'],
['day' => 'thursday', 'time' => '08:00-20:00'],
['day' => 'friday', 'time' => '08:00-20:00'],
['day' => 'saturday', 'time' => '10:00-16:00'],
['day' => 'sunday', 'time' => '10:00-16:00'],
];
$result = $active = [];
$openingHours[] = ['day' => '', 'time' => '']; // empty value to simplify code
foreach ($openingHours as $openingHour) {
if ($active) {
if ($active['time'] === $openingHour['time']) {
$active['end'] = $openingHour['day'];
} else {
$key = $active['end'] ? $active['start'] . '-' . $active['end'] : $active['start'];
$result[$key] = $active['time'];
$active = [];
}
}
$active = $active ?: [
'time' => $openingHour['time'],
'start' => $openingHour['day'],
'end' => null,
];
}
print_r($result);