2016-02-01 37 views
-2

print_r($data['SearchAvailResponse']['Hotel'])結果:如何查找數組的最小值?

Array 
(
    [0] => Array 
     (
      [HotelNo] => 1  
      [HCode] => IDJKT_00085 
      [Name] => Cebu Grand Hotel  
      [Currency] => USD 
      [TotalRate] => 56   
     ) 

    [1] => Array 
     (
      [HotelNo] => 2   
      [HCode] => IDJKT_00094 
      [Name] => Best Western Plus Lex Cebu   
      [Currency] => USD 
      [TotalRate] => 65  
     ) 

    [2] => Array 
     (
      [HotelNo] => 3   
      [HCode] => IDJKT_00102 
      [Name] => Best Western Sand Bar   
      [Currency] => USD 
      [TotalRate] => 93 
     ) 

    [3] => Array 
     (
      [HotelNo] => 4   
      [HCode] => IDJKT_00106 
      [Name] => Goldberry Suites & Hotel   
      [Currency] => USD 
      [TotalRate] => 51  
     ) 
) 

TotalRate標籤是酒店價格

我想找到的所有酒店

如何找到的所有酒店的最低價格最低的價格?

任何幫助非常讚賞

乾杯

回答

2
$cheapesthotel = array(); 
foreach($data['SearchAvailResponse']['Hotel'] as $hotel){ 
    if($cheapesthotel == array()){ 
     $cheapesthotel = $hotel; 
    } elseif ($hotel['TotalRate'] < $cheapesthotel['TotalRate']){ 
     $cheapesthotel = $hotel; 
    } 
} 
+0

它的工作。非常感謝你 –

+0

我需要你的幫助。看看這裏:http://stackoverflow.com/questions/38517387/how-to-multiply-number-until-achieve-single-digit-numbers-and-counting-the-numbe –

0
function getMin($array) 
{ 
$currentMin = 10000; 
$minObject = Array(); 
foreach($array as $val) 
{ 
    if($val[totalRate] < $currentMin) 
    { 
     $minObject = $val; 
    } 


} 

return minObject; 
}