function day($shop_id, $day){
return Shifts::find()->andWhere(['shop_id' => $shop_id, 'date' => date('Y-m-d 00:00:00', strtotime($day))])->all();
}
// Эту функцию можно перенести в модель как метод Shops::getShiftsByDay($day)
//{
// return Shifts::find()->andWhere(['shop_id' => $this->id, 'date' => date('Y-m-d 00:00:00', strtotime($day))])->all();
//};
function cell($start, $end, $employee){
echo Yii::$app->formatter->asTime($start, 'php:H:i').'-'.Yii::$app->formatter->asTime($end, 'php:H:i').' '.Html::a($employee->user->lastNameEmployee, ['shifts/update', 'id' => $employee->id], ['class' => 'button-editShifts', 'data-pjax' => 0]).'<br>';
}
// Эту функцию тоже можно перенести в модель Shifts::getFormattedTime()
//{
// return sprintf('%s - %s %s', Yii::$app->formatter->asTime($this->start_time, 'php:H:i'), Yii::$app->formatter->asTime($this->end_time, 'php:H:i'), Html::a($this->user->lastNameEmployee, ['shifts/update', 'id' => $this->id], ['class' => 'button-editShifts', 'data-pjax' => 0]));
//}
$weekDays = [
'Пн' => "last Monday",
'Вт' => 'last Tuesday',
// и тд
];
<table class="table">
<tr>
<th>Магазины</th>
<?php foreach($weekDays as $shortname => $time): ?>
<th><?= $shortname ?> <?= date("d.m", strtotime($time)) ?></th>
<?php endforeach; ?>
</tr>
<?php foreach ($shops as $shop): ?>
<tr>
<td><?= $shop->name ?></td>
<?php foreach($weekDays as $time): ?>
<td>
<?php
$employeeData = array_map(function(Shifts $employee){ return $employee->getFormattedTime(); }, $shop->getShiftsByDay($time));
echo implode('<br>', $employeeData);
?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
} ?>
</table>