A1 2014-10-1 10:00:00
A2 2014-10-2 14:00:00
B1 2014-10-4 13:00:00
B2 2014-10-5 15:00:00
A1 is start time, A2 is end time, B1 is start time, B2 is end time
Now there's time C1-C2
How to Judge C1-c2, if in A1-A2 or b1-b2 inside or have cross, appear the box hint.
Reply to discussion (solution)
Convert to timestamp and compare size
Observe a fact
$ar = Array ( ' A1 ' = ' 2014-10-1 10:00:00 ', ' A2 ' = ' 2014-10-2 ' 14:00:00 ', ' B1 ' = ' 2014-10-4 13:00:00 ', ' B2 ' = ' 2014-10-5 15:00:00 ',); $ar [' C1 '] = ' 2014-10-3 13:00:00 '; $ar [' C2 '] = ' 2014-10-5 13:00:00 '; Asort ($ar); Print_r ($ar);
Array ( [A1] = 2014-10-1 10:00:00 [A2] = 2014-10-2 14:00:00 [C1] = 2014-10-3 13:00:00 [B1] =& Gt 2014-10-4 13:00:00 [C2] = 2014-10-5 13:00:00 [B2] = 2014-10-5 15:00:00)
According to the key name can be accurately judged out of it?
Observe a fact
$ar = Array ( ' A1 ' = ' 2014-10-1 10:00:00 ', ' A2 ' = ' 2014-10-2 ' 14:00:00 ', ' B1 ' = ' 2014-10-4 13:00:00 ', ' B2 ' = ' 2014-10-5 15:00:00 ',); $ar [' C1 '] = ' 2014-10-3 13:00:00 '; $ar [' C2 '] = ' 2014-10-5 13:00:00 '; Asort ($ar); Print_r ($ar);
Array ( [A1] = 2014-10-1 10:00:00 [A2] = 2014-10-2 14:00:00 [C1] = 2014-10-3 13:00:00 [ B1] = 2014-10-4 13:00:00 [C2] = 2014-10-5 13:00:00 [B2] = 2014-10-5 15:00:00)
According to the key name can be accurately judged out of it?
This is an example where the actual data is a bunch of arrays
No matter how much data you have, the algorithm is constant.
As long as you check the key names in turn, the start and end of the group are not adjacent to each other, with cross or nested
The reason for not writing specific code is that your situation is much more complicated than the example, and you can't put it up. The key is understanding.