2013-06-27 66 views
1

我有一個數組,我想根據天數來改變車輛價格,這裏是我的數組想要重寫數組,我得到天數我得到$ rental_days並基於總價格是乘以,現在我想改變它,如果天是1,2,3,4比收費將適用如果5,6,7比最後價格將適用於那麼我應該如何重寫基於這種情況的數組(TOTAL_PRICE)?根據條件重寫php數組

 $vehicles[$result['vehicle_id']] = array(
      'vehicle_id' => $result['vehicle_id'], 
      'title'   => $result['manufacturer']." ".$result['series'], 
      'manufacturer' => $result['manufacturer'], 
      'series'  => $result['series'], 
      'year'   => $result['year'], 
      'class'   => $result['class'], 
      'image'   => $image, 
      'image_thumb' => $image_thumb, 
      'description' => $description, 
      'seats'   => $vehicle_meta['seats'], 
      'doors'   => $vehicle_meta['doors'], 
      'conditioning' => $vehicle_meta['conditioning'], 
      'transmission' => $vehicle_meta['transmission'], 
      'total_price'  => $rc_currency->format($rental_days*$result['rent']), 
      'daily_price'  => $rc_currency->format($result['rent']) 
     ); 
+0

你是什麼意思'重寫數組',你想只是更新當前陣列?更新當前數據庫結果?只需重寫一個新的數組?什麼? – KyleK

+0

我根據天數得到數組'total_price'的結果,但我想根據天數來更改此值。例如,如果沒有天數大於4,那麼我們將在第5,6,7天收取相同的費用爲期8天的新費用將被應用 – user2477139

回答

1

如果我理解正確....

做你的if語句來檢查天,然後充電適用於總在底部

不知道,如果你想申請收費一次,或次數的天數以及...我會留給你找出

 if(($rental_days>0)&&($rental_days<=4)){ 
     $charge = 12.00; //whatever you charge for 4 days 
     } elseif(($rental_days>4)&&($rental_days<=7)){ 
     $charge = 25.00; //whatever you charge for 567 days 
     } elseif($rental_days>7){ 
     $charge = 40.00; //whatever you charge for 8 days 
     } else {$charge = 0;} 

     $vehicles[$result['vehicle_id']] = array(
     'vehicle_id' => $result['vehicle_id'], 
     'title'   => $result['manufacturer']." ".$result['series'], 
     'manufacturer' => $result['manufacturer'], 
     'series'  => $result['series'], 
     'year'   => $result['year'], 
     'class'   => $result['class'], 
     'image'   => $image, 
     'image_thumb' => $image_thumb, 
     'description' => $description, 
     'seats'   => $vehicle_meta['seats'], 
     'doors'   => $vehicle_meta['doors'], 
     'conditioning' => $vehicle_meta['conditioning'], 
     'transmission' => $vehicle_meta['transmission'], 
     'total_price'  => $rc_currency->format(($rental_days*$result['rent'])+$charge), 
     'daily_price'  => $rc_currency->format($result['rent']) 
    ); 
+0

這是更好的方式,而不是在數組內寫入或放置任何條件語句 – user2477139