What are some alternative methods, besides using date functions, for displaying a weekly schedule in PHP?
When displaying a weekly schedule in PHP, an alternative method to using date functions is to create an array that represents each day of the week and then populate it with the desired schedule information. This can be useful when the schedule does not necessarily align with specific dates but rather with days of the week.
// Create an array representing each day of the week
$days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
// Populate the array with schedule information
$schedule = [
'Monday' => '9:00 AM - 5:00 PM',
'Tuesday' => '10:00 AM - 6:00 PM',
'Wednesday' => 'Off',
'Thursday' => '9:00 AM - 5:00 PM',
'Friday' => '10:00 AM - 6:00 PM',
'Saturday' => 'Off',
'Sunday' => 'Off'
];
// Display the weekly schedule
foreach ($days as $day) {
echo $day . ': ' . $schedule[$day] . '<br>';
}