How can a PHP developer efficiently loop through multiple time ranges retrieved from a MySQL query to determine website access restrictions?

To efficiently loop through multiple time ranges retrieved from a MySQL query to determine website access restrictions, a PHP developer can use a foreach loop to iterate over the results and check if the current time falls within any of the time ranges. This can be achieved by converting the time ranges into Unix timestamps and comparing them with the current Unix timestamp. If a match is found, the user can be granted access; otherwise, access can be restricted.

// Assuming $timeRanges is an array of time ranges retrieved from MySQL query
$currentTimestamp = time();

foreach ($timeRanges as $range) {
    $startTime = strtotime($range['start_time']);
    $endTime = strtotime($range['end_time']);

    if ($currentTimestamp >= $startTime && $currentTimestamp <= $endTime) {
        // User has access within this time range
        // Grant access here
    } else {
        // User does not have access within this time range
        // Restrict access here
    }
}