How can PHP be used to create a shift schedule with a repeating cycle?

Creating a shift schedule with a repeating cycle in PHP can be achieved by defining an array of shifts and then using a loop to assign shifts to specific dates based on the repeating cycle. By calculating the index of the shift in the array for each date, a shift schedule can be generated with a repeating pattern.

<?php
// Define the array of shifts in the repeating cycle
$shifts = ['Morning', 'Afternoon', 'Night'];

// Define the start date and number of days in the schedule
$start_date = strtotime('2022-01-01');
$num_days = 30;

// Loop through each day and assign a shift based on the repeating cycle
for ($i = 0; $i < $num_days; $i++) {
    $shift_index = $i % count($shifts);
    $date = date('Y-m-d', strtotime("+$i days", $start_date));
    echo "Date: $date - Shift: $shifts[$shift_index] <br>";
}
?>