How can I effectively determine whether there are intersection data ranges?

Source: Internet
Author: User
How can I effectively determine whether there are intersection of several groups of data ranges between 5000 and ~ 70002000 ~ 60008000 ~ 90004000 ~ 85005000 ~ 7000 could you tell me how many random data sets in php can be used to determine whether there are duplicates more effectively? The expected value is 2000 ~ 40004000 ~ 50005000 ~ 60006000 ~ 70007000 ~ 85008500 ~ 9000 how can I effectively determine whether there are multiple sets of data ranges?
5000 ~ 7000
2000 ~ 6000
8000 ~ 9000
4000 ~ 8500
5000 ~ 7000
In php, how can we more effectively judge whether there are duplicates of these groups of random data?

Expected value:
2000 ~ 4000
4000 ~ 5000
5000 ~ 6000
6000 ~ 7000
7000 ~ 8500
8500 ~ 9000

Php

Share:


------ Solution --------------------
You only need to determine whether the content is included. you can write it as a function.
Continue with the idea
$a = array(
array(5000, 7000),
array(2000, 6000),
array(8000, 9000),
array(4000, 8500),
array(5000, 7000),
);
var_dump(foo($a)); //bool(false)

$a = array(
array(5000, 7000),
array(6000, 8200),
array(8000, 9000)
);
var_dump(foo($a)); //bool(false)

$a = array(
array(5000, 5500),
array(6000, 6500),
array(8000, 8500)
);
var_dump(foo($a)); //bool(true)

function foo($a) {
$r = array_unique(call_user_func_array('array_merge', $a));
sort($r);

foreach($a as $v) {
if(array_search($v[0], $r) != array_search($v[1], $r) - 1) return false;
}
return true;
}

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.