Skip to content

Instantly share code, notes, and snippets.

@ErMandeep
Created May 6, 2021 10:41
Show Gist options
  • Save ErMandeep/4e870e8175726951f3241579bccea7dc to your computer and use it in GitHub Desktop.
Save ErMandeep/4e870e8175726951f3241579bccea7dc to your computer and use it in GitHub Desktop.
Detect overlapping periods php
$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