日费率折扣


Day rate discount

我正在为一家汽车租赁公司创建一个内部网

我将默认价格设置为:

$dayRate = '90.00';

如果需要,我在表上创建了一个字段来存储折扣日费率,称为disc_day_rate,默认值为0。

我把折扣价作为

$discDayRate = $hire['disc_day_rate'];

我想找到这两个数字中最低的一个,但我认为默认的disc_day_rate为0会导致问题

我尝试过使用min();if ($discDayrate == "0")方法,但在stackoverflow上找到了许多答案,而不必发布我自己的答案。是时候寻求优雅解决方案的帮助了

这样可以确保0.00永远不会给您带来问题。

if ($discDayRate == 0.00) { ## don't use quotes here; it should be saved as a DECIMAL or INT in the database
   $the_rate = $dayRate; ## back to the default
}
else {
   if ($discDayRate < $dayRate) {
      $the_rate = $diskDayRate;
   }
   else {
      $the_rate = $dayRate;
   }
}

$the_rate有您想要的价格。