3

以下のように2つのPHP配列があります

配列 1 - 予算の開始

Array
(
    [0] => 25000
    [1] => 30000
    [2] => 35000
    [3] => 15900
)

配列 2 - 予算の終了

Array
(
    [0] => 40000
    [1] => 50000
    [2] => 60000
    [3] => 55000
)

ユーザーが実際に探している予算範囲をフィルタリングしたい.上記の予算範囲は、予算開始の場合は 35000、予算終了の場合は 40000 です。

予算開始は、すべての予算開始を他のすべての予算開始と比較して計算されるため、予算開始は予算開始と予算終了の間にある必要があります。

予算開始 35000 理由

25000 <= 35000 < 40000
30000 <= 35000 < 50000
35000 <= 35000 < 60000
15900 <= 35000 < 55000

予算終了 40000 理由

25000 < 40000 <= 40000
30000 < 40000 <= 50000
35000 < 40000 <= 60000
15900 < 40000 <= 55000

これを解決する方法はありますか。

返信ありがとう

4

1 に答える 1

1
<?php
$start = Array(25000,30000,35000,15900);

$end = Array(40000,50000,60000,55000);


foreach($start as $val){
    $cnt = 0;
    for($i=0;$i<count($start); $i++){
        if($start[$i] <= $val && $val < $end[$i]){
            $cnt++;
        }
        if($cnt == count($start)){
            $start_budget = $val;
        }
    }
}

foreach($end as $val){
    $cnt = 0;
    for($i=0;$i<count($end); $i++){
        if($start[$i] < $val && $val <= $end[$i]){
            $cnt++;
        }
        if($cnt == count($end)){
            $end_budget = $val;
        }
    }
}

echo $start_budget;
echo "<br>";
echo $end_budget;
?>
于 2013-02-05T05:27:48.943 に答える