I have a Two PHP arrays as Below

Array 1 – Budget Start
$start = Array(25000,30000,35000,15900);

Array 2 – Budget End
$end = Array(40000,50000,60000,55000);

I want to Filter the Budget range which the user is actually looking for.For the above the budget range is 35000 For Budget Start and 40000 for Budget End.

Budget Start 35000 because
25000 <= 35000 < 40000
30000 <= 35000 < 50000
35000 <= 35000 < 60000
15900 <= 35000 < 55000

Budget End 40000 because
25000 < 40000 <= 40000
30000 < 40000 <= 50000
35000 < 40000 <= 60000
15900 < 40000 <= 55000

$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 "
";
echo $end_budget;
Posted in PHP.

Leave a reply