次のコードスニペットがあります。これは機能し、必要な処理を実行します。唯一の問題は、それが少し「冗長」であり、いくつかの最適化で実行できると思うことです。可能であれば、誰かが繰り返しを減らすのを手伝ってくれませんか。ほとんどのコードは非常に似ています...
どうもありがとう
<?php
// condition = Less Than; More Than; Between
// noofweeks = this is the number of weeks chosen by the user
function fmsSupplements($condition, $conditionWeeks, $noofweeks, $weekno, $weekStartno, $weekEndno, $basicprice, $supplementAmnt, $supplementType) {
if ($condition== "Between") {
// I need to get the start and end values as the data in this parameter should look like 1-17
$betweenArray = explode('-',$conditionWeeks);
$startWeek = $betweenArray[0];
$endWeek = $betweenArray[1];
}
if(($condition == "Less Than") && ($noofweeks < $conditionWeeks) && ($supplementType == 'Subtract') && ($weekno >= $weekStartno && $weekno <= $weekEndno) ) { return $basicprice - $supplementAmnt; }
elseif(($condition == "Less Than") && ($noofweeks < $conditionWeeks) && ($supplementType == 'Add') && ($weekno >= $weekStartno && $weekno <= $weekEndno) ) { return $basicprice + $supplementAmnt; }
elseif(($condition == "More Than") && ($noofweeks > $conditionWeeks) && ($supplementType == 'Subtract') && ($weekno >= $weekStartno && $weekno <= $weekEndno) ) { return $basicprice - $supplementAmnt; }
elseif(($condition == "More Than") && ($noofweeks > $conditionWeeks) && ($supplementType == 'Add') && ($weekno >= $weekStartno && $weekno <= $weekEndno) ) { return $basicprice + $supplementAmnt; }
elseif(($condition == "Between") && ($noofweeks >= $startWeek && $noofweeks <= $endWeek) && ($supplementType == 'Add') && ($weekno >= $weekStartno && $weekno <= $weekEndno) ) { return $basicprice + $supplementAmnt; }
elseif(($condition == "Between") && ($noofweeks >= $startWeek && $noofweeks <= $endWeek) && ($supplementType == 'Substract') && ($weekno >= $weekStartno && $weekno <= $weekEndno) ) { return $basicprice - $supplementAmnt; }
//if no conditions match, just return the unaltered basic price back
else { return $basicprice ;}
;} ?>