How can you assign different values based on specific ranges of time in PHP?

To assign different values based on specific ranges of time in PHP, you can use conditional statements like if-else or switch-case to check the current time and assign values accordingly. For example, you can check if the current time falls within a certain range (e.g., morning, afternoon, evening) and assign different values based on that.

$current_time = date("H");

if ($current_time < 12) {
    $value = "Morning";
} elseif ($current_time < 18) {
    $value = "Afternoon";
} else {
    $value = "Evening";
}

echo "Current time: " . date("H:i") . "\n";
echo "Value based on time range: " . $value;