Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP函数中计算时,函数名必须为字符串_Php_Function - Fatal编程技术网

在PHP函数中计算时,函数名必须为字符串

在PHP函数中计算时,函数名必须为字符串,php,function,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 (isse

我试图在我的代码中进行计算,结果出现了一个错误

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;
    }
}

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

您缺少了乘法的
*
运算符;如果没有这个函数,您将尝试调用
$investment
,但它包含一个数字。您需要使用
pow()
函数进行幂运算<代码>^是按位异或

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

$investment(1+$interest\u rate/12)
应该做什么计算?它们之间需要一个算术运算符。如果没有运算符,看起来您正在尝试将
$investment
作为函数调用。而且,
^
在PHP中不是求幂运算,您需要调用
pow()
函数。谢谢!我在想数学。哈!回答得好!