Compare and loop time ranges in PHP.