How can PHP arrays and foreach loops be utilized to simplify and improve the efficiency of time-based condition checks?

When dealing with multiple time-based condition checks in PHP, it can become tedious and inefficient to write out each condition individually. By utilizing PHP arrays to store the conditions and using a foreach loop to iterate over them, you can simplify the code and improve its efficiency.

// Define an array of time-based conditions
$timeConditions = [
    'morning' => ['start' => '06:00:00', 'end' => '12:00:00'],
    'afternoon' => ['start' => '12:00:00', 'end' => '18:00:00'],
    'evening' => ['start' => '18:00:00', 'end' => '00:00:00']
];

// Get the current time
$currentTime = date('H:i:s');

// Iterate over the time conditions
foreach ($timeConditions as $key => $condition) {
    if ($currentTime >= $condition['start'] && $currentTime < $condition['end']) {
        echo "It is currently $key.";
        break;
    }
}