Got it!
function getEcoPrice($distance, $persons, $doubleTour) {
$distance = ceil($distance); //round up to next integer
$startPrice = 69;
$endprice = $startPrice;
$amountPlusPerson = array(0, 0, 20, 20, 10, 10, 10, 10, 10); //first index is just for setting index = number of persons. value to add, if extra person.
$amountNextDistance = array(0, 10, 10, 10, 10, 10, 10, 10, 10); //first index is just for setting index = number of distance steps. value to add, if next distance is reached.
$amountDoubleTour = array(-20, -20, -20, -20, -20, -20, -20, -20, -20); //value to add, if doubleTour is enabled.
$index = 0;
switch (true) {
case $distance <= 130:
$index = 0;
break;
case $distance <= 160:
$index = 1;
break;
case $distance <= 170:
$index = 2;
break;
case $distance <= 180:
$index = 3;
break;
case $distance <= 190:
$index = 4;
break;
case $distance <= 200:
$index = 5;
break;
case $distance <= 210:
$index = 6;
break;
case $distance <= 220:
$index = 7;
break;
case $distance <= 230:
$index = 8;
break;
case $distance > 230:
return 99999;
break;
}
for($i = 0; $i <= $index; $i++) {
$endprice += $amountNextDistance[$i];
};
for ($i = 0; $i <= $persons; $i++) {
$endprice += $amountPlusPerson[$i];
}
if ($doubleTour) {
$endprice = $endprice * 2 + $amountDoubleTour[$index];
}
return $endprice;
}
函數調用:
echo getEcoPrice(200.1, 2, false);
您已經標記了這個問題,用'phpexcel':你其實看着[PHPExcel(https://github.com/PHPOffice/PHPExcel) ? –
是的,但這應該是最後一個選項。我們希望保持系統苗條,不要那麼多第三方課程。 – djsined
這是你的選擇....你問最簡單的方法來實現它;我指出了最簡單的方法....當然,您可以自己編寫所有計算邏輯,使用普通的PHP –