1

我有一个数组,我想根据天数更改车辆价格这里是我的数组想要重写数组,我得到了我得到 $rental_days 的天数,并且基于该总价格相乘,现在我想改变它这样,如果天数为 1、2、3、4,则如果 5、6、7 比最后价格适用,则将收取费用,那么我应该如何根据此条件重写数组(total_price)?

        $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'])
        );
4

1 回答 1

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'])
    );
于 2013-06-27T02:48:54.973 回答