Is using arrays as the primary data structure for opening hours in PHP a common and recommended approach in the industry?
Using arrays as the primary data structure for opening hours in PHP is a common and recommended approach in the industry. Arrays provide a flexible way to store and manipulate opening hours data, allowing for easy access and modification.
// Example of using arrays for opening hours data
$openingHours = [
'Monday' => ['09:00', '17:00'],
'Tuesday' => ['09:00', '17:00'],
'Wednesday' => ['09:00', '17:00'],
'Thursday' => ['09:00', '17:00'],
'Friday' => ['09:00', '17:00'],
'Saturday' => ['10:00', '14:00'],
'Sunday' => 'Closed'
];
// Accessing opening hours for a specific day
$day = 'Monday';
if (isset($openingHours[$day])) {
echo "Opening hours for $day: " . implode(' - ', $openingHours[$day]);
} else {
echo "Opening hours for $day are not available.";
}