Using PHP echo()
Using echo()
statements to trace code execution
// calculate the future value
$investment = 1000;
$interest_rate = .2;
$years = 10;
$future_value = $investment;
echo("$future_value: " . $future_value . "<br>");
echo("$interest_rate: " . $interest_rate . "<br>");
echo("$years: " . $years . "<br>");
echo("For loop for calculating future value is starting...<br><br>");
for ($i = 1; $i <= $years; $i++) {
$future_value += $future_value * $interest_rate;
echo("$i: " . $i . "<br>");
echo("$future_value: " . $future_value . "<br>");
}
Output
$future_value: 1000
$interest_rate: 0.2
$years: 10
For loop for calculating future value is starting...
1: 1
$future_value: 1200
2: 2
$future_value: 1440
3: 3
$future_value: 1728
4: 4
$future_value: 2073.6
5: 5
$future_value: 2488.32
6: 6
$future_value: 2985.984
7: 7
$future_value: 3583.1808
8: 8
$future_value: 4299.81696
9: 9
$future_value: 5159.780352
10: 10
$future_value: 6191.7364224
Back