What is the best way to implement a schedule system in PHP to display current programs based on time?
To implement a schedule system in PHP to display current programs based on time, you can create an array of program schedules with start and end times. Then, iterate through the array to find the current program based on the current time. Finally, display the details of the current program.
<?php
// Define program schedules with start and end times
$programSchedules = array(
array("name" => "Program A", "start" => "08:00", "end" => "10:00"),
array("name" => "Program B", "start" => "10:00", "end" => "12:00"),
array("name" => "Program C", "start" => "12:00", "end" => "14:00"),
);
// Get current time
$current_time = date("H:i");
// Iterate through program schedules to find the current program
$current_program = "";
foreach ($programSchedules as $program) {
if ($current_time >= $program["start"] && $current_time < $program["end"]) {
$current_program = $program["name"];
break;
}
}
// Display current program
echo "Current program: " . $current_program;
?>