判断多个区间是否有交集

 '1', 'act_price_z' => '10'],
        ['act_price_a' => '20', 'act_price_z' => '30'],
        ['act_price_a' => '31', 'act_price_z' => '40'],
];
$actprice = [];
foreach ($a as $_v) {
    if (isset($_v['act_price_a']) && isset($_v['act_price_z'])) {
        $actprice[$_v['act_price_a']] = $i;
        $actprice[$_v['act_price_z']] = $i++;
    }
}
ksort($actprice);
$tmp = '';
$difTime = 0;
foreach ($actprice as $item) {
    if ($tmp == '') {
        $tmp = $item;
    } else {
        if ($tmp == $item) {
            $tmp = $item;
            $difTime = 0;
        } else {
            $tmp = $item;
            $difTime++;
            if ($difTime >= 2) {
                echo '预售定金规则活动价区间有交叉,请检查重填';
                break;
            }
        }
    }
}

你可能感兴趣的:(算法复杂度)