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

"); echo("\$interest_rate: " . $interest_rate . "
"); echo("\$years: " . $years . "
"); echo("For loop for calculating future value is starting...

"); for ($i = 1; $i <= $years; $i++) { $future_value += $future_value * $interest_rate; echo("$i: " . $i . "
"); echo("\$future_value: " . $future_value . "
"); } ?>

Back