【发布时间】:2019-01-04 16:46:10
【问题描述】:
有没有一种快速的方法可以根据天数降低租金?
例如:
If I rent a car for 1day, the cost is 100$
If I rent a car for 2days, the cost is 100$ + 70$ = 170$
If I rent a car for 3days, the cost is 100$ + 70$ + 50$ = 220$
If I rent a car for 4days, the cost is 100$ + 70$ + 50$ + 50$ = 270$
If I rent a car for 5days, the cost is 100$ + 70$ + 50$ + 50$ + 50$ = 320$
所以我需要一种快速的方法来根据天数计算总费用。 例如:
function getcost(days){
...
return $cost;
}
echo getcost(1); // it show 100$
echo getcost(3); // it show 220$
// and so on...
【问题讨论】:
-
switch 语句?
-
或者,编号数组 ($array[1 => 100, 2 => 70, 3 => 50]) - 所以
function calcPrice($days) {#add up accordingly based on number of days (if above 3 keep @ 50)} -
那么,这是你的作业吗?
标签: php calculation