Judgment of overlapping regions of multiple time periods in php

$times=[
0=>"08:00-09:00"
1=>"09:20-13:00"
2=>"14:00-18:00"
3=>"19:00-20:00"
];

there are a large number of such time arrays, all of which are reservation information. Now that the customer has selected an appointment time, I want to determine whether there is any overlap between the given time and the one already booked. For example, if you give 08:30-10 time 00, then this time will partially overlap with $time [0] and $time [1]. My practice is to sort the array I have booked at 70 points, and use foreach to traverse it. If there is an overlap, I will output the first time segment with overlap, but I think there may be a better solution. The time period is like a line with a start and end point. I project all the time periods onto the x-axis. You can tell where there is overlap at a moment"s notice. Can you give me a specific method? Thank you.

clipboard.png

Php
Nov.09,2021

//
Menu