Time judgment problems

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.