array to return on conditions 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 =&gt;
    array
            'id' =&gt; 83739000038374
            'special-price' =&gt; 99.99
            'retail-price' =&gt; 199
1 =&gt;
    array
            'id' =&gt; 83739000038374
            'special-price' =&gt; 199.99
            'retail-price' =&gt; 299
2 =&gt;
    array
            'id' =&gt; 83739000038374
            'special-price' =&gt; 89
            'retail-price' =&gt; 129
3 =&gt;
    array
            'id' =&gt; 83739000038374
            'special-price' =&gt; 179
            'retail-price' =&gt; 329


my code is 

public function getPriceRange(){
    $priceRange = array();
    $showRange = true;
    if($originalArray &amp;&amp; count($originalArray) &gt; 1){
        foreach($originalArray as $idx =&gt; $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'] &gt; $priceRange['price']['max'] ){
                    $priceRange['price']['max'] = is_int($originalArraySingle['price']) ? number_format((float)$originalArraySingle['price'], 2, '.', '') : $originalArraySingle['price'];
                }
                if($originalArraySingle['price'] &lt; $priceRange['price']['min'] ){
                    $priceRange['price']['min'] = is_int($originalArraySingle['price']) ? number_format((float)$originalArraySingle['price'], 2, '.', '') : $originalArraySingle['price'];
                }
                if($originalArraySingle['original-price'] &gt; $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'] &lt; $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.
if($originalArraySingle['original-price'] &lt; $priceRange['original-price']['min']){
    $priceRange['original-price']['min'] = is_int($originalArraySingle['original-price']) ? number_format((float)$originalArraySingle['original-price'], 2, '.', '') : $originalArraySingle['original-price'];
}


You could write a function for this. And one for maximize.

protected function minimize($a,&amp;$b){
    if($a&lt;$b){
        $b = is_int($a)?number_format((float)$a,2,'.',''):$a;
    }
}


I would also write.

if($priceRange['price']['max']===$priceRange['price']['min'] ||  $priceRange['price']['max']===$priceRange['price']['min']){
        return null;
    }


and change 

return $showRange ? $priceRange : null;


to

return $priceRange;


so you have one variable less.