如何使用正确的开关或条件声明?

时间:2015-10-13 07:22:53

标签: php arrays if-statement switch-statement

你能帮我解决这个问题:

为此

  

$ share Value< = 30000该期限为1 - 36,第一次为1.3%   下一学期.65的期限和递减值,而$ share值> = 30001,递减值0.75

    <?php
// Create a function that can accept parameters
function CalculateItem($share = 0,$terms = 0)
    {
        if($share <= 30000)
            $multiplier =   ($terms == "1")? .0130 : .0195;
        elseif($share >= 30001)
            $multiplier =   ($terms == "1")? .0130 : .0205;

        if(empty($multiplier))
            return;

        $data['share']              =   $share;
        $data['terms']              =   $terms; 
        $data['interest']           =   ($share * $multiplier);                     
        $data['service_fee']        =   ($share * .01);
        $data['filling_fee']        =   30;
        $data['cash_on_hand']       =   $share - ($data['service_fee'] + $data['interest'] + $data['filling_fee']);
        $data['loan_receivable']    =   $data['cash_on_hand'] + $data['service_fee'] + $data['interest'] + $data['filling_fee'];
        $data['debit']              =   $data['loan_receivable'];
        $data['credit']             =   $data['interest'] + $data['service_fee'] + $data['filling_fee'] + $data['cash_on_hand'];

        return $data;
    }

// Get the state of data. Anything but false will trigger the breakout table
$data   =   (isset($_POST['calculate']))? CalculateItem($_POST['share'],$_POST['terms']) : false;
?>

1 个答案:

答案 0 :(得分:0)

虽然费率是固定的,但你可以这样做 -

$rate=.0130;
 if($share <= 30000)
            $multiplier =   $rate + ($terms-1)*(0.65);
        elseif($share >= 30001)
            $multiplier =   $rate + ($terms-1)*(0.75);

通过这种方式,您可以按照所有条款计算