函数名必须是PHP函数中的计算字符串

时间:2017-03-24 19:48:53

标签: php function

我正在尝试在我的代码中进行计算,并且出现错误

Fatal error: Function name must be a string on line 3


function compound_interest($compound_interest, $compound_interest_f, $investment, $interest_rate, $years, $compoundMonthly, $future_value_f, $future_value) {
    if (isset($compoundMonthly)) {
        $compoundMonthly = 'Yes';
        $compound_interest = ($investment(1 + $interest_rate / 12)^(12 * $years) - $investment);
        $compound_interest_f = '$' . number_format($compound_interest, 2);
        return $compound_interest_f;
    } else {
        $compoundMonthly = 'No';
       $future_value = ($future_value + ($future_value * $interest_rate * .01));
        $future_value_f = '$' . number_format($future_value, 2);
        return $future_value_f;
    }
}

只有该行的代码正在尝试进行计算。不打印字符串。我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

你错过了*运算符进行乘法运算;没有这个,你试图将$investment称为函数,但它包含一个数字。并且您需要使用pow()函数进行取幂; ^有点XOR。

$compound_interest = $investment * pow((1 + $interest_rate / 12), 12 * $years) - $investment;