2017-03-24 46 views
-1

我試圖做一個計算在我的代碼,並將其與功能名稱必須是PHP函數的計算串

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

一個錯誤出現只有在該行的代碼試圖做一個計算。不打印字符串。我在這裏錯過的任何東西?

+2

'$ investment(1 + $ interest_rate/12)'應該做什麼計算?你需要一個算術運算符。 – Barmar

+3

沒有運營商,它看起來像你試圖調用'$投資'作爲一個函數。 – Barmar

+2

另外,'^'不是PHP中的指數,你需要調用'pow()'函數。 – Barmar

回答

1

您錯過了用於乘法的*運算符;沒有這個,你試圖撥打$investment作爲一個函數,但它包含一個數字。你需要使用pow()函數來取冪; ^是按位異或。

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

謝謝!我在那裏想寫數學。哈!很好的答案! – HawkBlade124

相關問題