How can PHP be used to efficiently iterate through groups and assign them to available slots in a schedule?

To efficiently iterate through groups and assign them to available slots in a schedule, we can use a combination of arrays and loops in PHP. We can create an array of groups and an array of available slots in the schedule. Then, we can iterate through each group and assign them to the first available slot in the schedule.

<?php

// Array of groups
$groups = ['Group A', 'Group B', 'Group C', 'Group D'];

// Array of available slots in the schedule
$schedule = ['Slot 1', 'Slot 2', 'Slot 3', 'Slot 4'];

// Iterate through each group and assign them to the first available slot
foreach ($groups as $group) {
    $assigned = false;
    
    foreach ($schedule as $key => $slot) {
        if (!$assigned) {
            echo $group . ' assigned to ' . $slot . PHP_EOL;
            unset($schedule[$key]);
            $assigned = true;
        }
    }
}

?>