I am writing a method to find me a price range for special price as well as the retail price. Such as in example below I have price range for retail from 129 to 329 where as special price range is 89 to 199
array
0 =>
array
'id' => 83739000038374
'special-price' => 99.99
'retail-price' => 199
1 =>
array
'id' => 83739000038374
'special-price' => 199.99
'retail-price' => 299
2 =>
array
'id' => 83739000038374
'special-price' => 89
'retail-price' => 129
3 =>
array
'id' => 83739000038374
'special-price' => 179
'retail-price' => 329
my code is
public function getPriceRange(){
$priceRange = array();
$showRange = true;
if($originalArray && count($originalArray) > 1){
foreach($originalArray as $idx => $originalArraySingle){
if($idx == 0){
$priceRange['price']['max'] = $originalArraySingle['price'];
$priceRange['price']['min'] = $originalArraySingle['price'];
$priceRange['original-price']['max'] = $originalArraySingle['original-price'];
$priceRange['original-price']['min'] = $originalArraySingle['original-price'];
}else{
if($originalArraySingle['price'] > $priceRange['price']['max'] ){
$priceRange['price']['max'] = is_int($originalArraySingle['price']) ? number_format((float)$originalArraySingle['price'], 2, '.', '') : $originalArraySingle['price'];
}
if($originalArraySingle['price'] < $priceRange['price']['min'] ){
$priceRange['price']['min'] = is_int($originalArraySingle['price']) ? number_format((float)$originalArraySingle['price'], 2, '.', '') : $originalArraySingle['price'];
}
if($originalArraySingle['original-price'] > $priceRange['original-price']['max'] ){
$priceRange['original-price']['max'] = is_int($originalArraySingle['original-price']) ? number_format((float)$originalArraySingle['original-price'], 2, '.', '') : $originalArraySingle['original-price'];
}
if($originalArraySingle['original-price'] < $priceRange['original-price']['min']){
$priceRange['original-price']['min'] = is_int($originalArraySingle['original-price']) ? number_format((float)$originalArraySingle['original-price'], 2, '.', '') : $originalArraySingle['original-price'];
}
}
}
//doesnt make sense to show price range if its same.
if($priceRange['price']['max']===$priceRange['price']['min'] || $priceRange['price']['max']===$priceRange['price']['min']){
$showRange = false;
}
}
return $showRange ? $priceRange : null;
}
I am looking for scalability and for fastest code processing.