If you have two ranges [b1, e1]
and [b2, e2]
(where it is already established that b1 < e1
and b2 < e2
) then the overlap is detected by the following logical expression
not (e2 < b1 or e1 < b2)
which can be rewritten as
e2 >= b1 and e1 >= b2
In your syntax that would be
if(($orange['end'] >= $red['start']) && ($red['end'] >= $orange['start'])) {
//Conflict handling
}
I.e. you got it correctly. Why you are claiming "Working through the numbers logically, I understand why the statement above fails." is not clear to me. What exactly fails? (And I don't know why is everyone coming up with ridiculously "overengineered" checks, with more than two comparisons.)
Of course, you have to decide whether touching ranges are considered overlapping and adjust the strictness of the comparisons accordingly.
P.S. The sample ranges you provided in your edit do not overlap, and your comparison correctly recognizes it as no-conflict situation. I.e. everything works as it should. Where do you see the problem?