How can I create Price Ranges from price array? Let\'s say I have this array which holds prices:
Array ( [0] => 500 [1] => 500 [2] => 520 [3] =&g
I made it automated; i didnt use classes but it is easily able to be converted.
$maxPRoductInRange){
//create bigger range chart
makeRangeChart($min,$max,$rangeChart);
calculateRange();
}
}
}
}
function checkProductCount($min,$max,$priceList){
global $chart;
$count=0;
$rest=0;
foreach( $priceList as $price){
if($price>=$min && $price<$max) {
$count++;
} else { $rest++; }
}
$chart[$min]=$count;
return array($count,$rest);
}
function makeRangeChart($min=0,$max,&$rangeChart){
$middleOfRange=($max+$min)/2;
$rangeChart[]=$min;
$rangeChart[]=$middleOfRange;
$rangeChart[]=$max;
$rangeChart=array_unique ($rangeChart);
sort($rangeChart, SORT_NUMERIC );
}
function printChart(){
global $chart,$highestPrice;
$minPrices=array_keys($chart);
$count=count($minPrices);
$line='';
for($a=0;$a<$count;$a++){
$line.=$minPrices[$a];
$line.=(isset($minPrices[$a+1]))?' - '.$minPrices[$a+1]:'+';
$line.='('.$chart[$minPrices[$a]].')
';
}
return $line;
}
calculateRange();
echo printChart();
?>