Created
May 6, 2021 10:41
-
-
Save ErMandeep/4e870e8175726951f3241579bccea7dc to your computer and use it in GitHub Desktop.
Detect overlapping periods php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$final_selected_time = ["10:20-11:30","11:20-12:40","15-20","16:00"]; | |
$results = []; | |
sort($final_selected_time, SORT_NUMERIC); | |
foreach ($final_selected_time as $k => $first) { | |
$firstNums = explode("-", $first); | |
foreach ($final_selected_time as $second) { | |
if ($first == $second) continue; | |
$secondNums = explode("-", $second); | |
if ($firstNums[0] <= $secondNums[0] && $secondNums[0] <= $firstNums[1]) { | |
// $results[$first] = $second; | |
$results[] = $secondNums[0]; | |
} | |
} | |
} | |
// output | |
11:20 | |
source link | |
https://stackoverflow.com/questions/37788249/detect-overlapping-periods-php | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment