| Employee |
format('D'); ?> format('M j'); ?> |
|---|---|
| format('Y-m-d'), $shifts); - |
1, 'name' => 'Daniel Miller'], ['id' => 2, 'name' => 'Sophia Chen'], ['id' => 3, 'name' => 'James Wilson'], ['id' => 4, 'name' => 'Olivia Garcia'], ]; // Get current week $date = new DateTime(); $week_start = clone $date; $week_start->modify('monday this week'); $days_of_week = []; for ($i = 0; $i < 7; $i++) { $days_of_week[] = (clone $week_start)->modify("+$i days"); } $shifts = [ // Monday ['date' => $days_of_week[0]->format('Y-m-d'), 'employee_id' => 1, 'start_time' => '08:00', 'end_time' => '16:00', 'location' => 'Main Office'], ['date' => $days_of_week[0]->format('Y-m-d'), 'employee_id' => 3, 'start_time' => '09:00', 'end_time' => '17:00', 'location' => 'Warehouse'], // Tuesday ['date' => $days_of_week[1]->format('Y-m-d'), 'employee_id' => 2, 'start_time' => '10:00', 'end_time' => '18:00', 'location' => 'Main Office'], // Wednesday ['date' => $days_of_week[2]->format('Y-m-d'), 'employee_id' => 1, 'start_time' => '08:30', 'end_time' => '16:30', 'location' => 'Remote'], ['date' => $days_of_week[2]->format('Y-m-d'), 'employee_id' => 4, 'start_time' => '11:00', 'end_time' => '19:00', 'location' => 'Main Office'], // Thursday ['date' => $days_of_week[3]->format('Y-m-d'), 'employee_id' => 2, 'start_time' => '09:00', 'end_time' => '17:00', 'location' => 'Warehouse'], ['date' => $days_of_week[3]->format('Y-m-d'), 'employee_id' => 3, 'start_time' => '12:00', 'end_time' => '20:00', 'location' => 'Main Office'], // Friday ['date' => $days_of_week[4]->format('Y-m-d'), 'employee_id' => 4, 'start_time' => '09:00', 'end_time' => '17:00', 'location' => 'Main Office'], ]; function find_shifts_for_employee_and_day($employee_id, $date, $shifts) { $result = []; foreach ($shifts as $shift) { if ($shift['employee_id'] == $employee_id && $shift['date'] == $date) { $result[] = $shift; } } return $result; } ?>
| Employee |
format('D'); ?> format('M j'); ?> |
|---|---|
| format('Y-m-d'), $shifts); - |