What are some best practices for organizing and iterating through arrays in PHP to efficiently handle and display data like opening hours?

When organizing and iterating through arrays in PHP to efficiently handle and display data like opening hours, it is important to structure the array in a logical way that allows for easy retrieval and manipulation of the data. One way to achieve this is by using a multidimensional array where each day of the week is a key and the opening hours are stored as values. By iterating through this array, you can easily access and display the opening hours for each day.

// Example of organizing opening hours in a multidimensional array
$opening_hours = [
    'Monday' => '9:00 AM - 5:00 PM',
    'Tuesday' => '9:00 AM - 5:00 PM',
    'Wednesday' => '9:00 AM - 5:00 PM',
    'Thursday' => '9:00 AM - 5:00 PM',
    'Friday' => '9:00 AM - 5:00 PM',
    'Saturday' => '10:00 AM - 2:00 PM',
    'Sunday' => 'Closed'
];

// Iterating through the array to display opening hours for each day
foreach ($opening_hours as $day => $hours) {
    echo $day . ': ' . $hours . PHP_EOL;
}