Time judgment problem A1 10:00:00
A2 2014-10-2 14:00:00
B1 13:00:00
B210-10-5 15:00:00
A1 indicates the start time, A2 indicates the end time, B1 indicates the start time, and B2 indicates the end time.
Now there is time C1-C2
How to determine the C1-C2, if there is a cross in the A1-A2 or B1-B2, a bullet box prompt appears.
Reply to discussion (solution)
Convert to timestamp and then compare the 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] => 2014-10-4 13:00:00 [C2] => 2014-10-5 13:00:00 [B2] => 2014-10-5 15:00:00)
Can I make an accurate judgment based on the key name?
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)
Can I make an accurate judgment based on the key name?
This is an example. the actual data is a bunch of arrays.
Algorithms remain unchanged no matter how much data is there.
As long as the key names are checked in sequence, the "start" and "end" of the same group are not adjacent to each other, that is, there is a cross or nested
The reason for not writing specific code is: your situation is far more complex than the example, and you cannot write it. The key lies in understanding