What are the potential pitfalls of using if-else constructs in PHP for time-based text output?

Using if-else constructs for time-based text output can lead to a cluttered and hard-to-maintain codebase, especially if there are multiple time conditions to check. Instead, a more scalable approach would be to use an array to store the time conditions and their corresponding text outputs, allowing for easier management and scalability.

// Time-based text output using an array
$times = [
    'morning' => 'Good morning!',
    'afternoon' => 'Good afternoon!',
    'evening' => 'Good evening!',
    'night' => 'Good night!'
];

$current_time = date('H');

if ($current_time >= 5 && $current_time < 12) {
    echo $times['morning'];
} elseif ($current_time >= 12 && $current_time < 17) {
    echo $times['afternoon'];
} elseif ($current_time >= 17 && $current_time < 20) {
    echo $times['evening'];
} else {
    echo $times['night'];
}