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;
}