Using a $debug Variable

I have a line in my vars.php file, $debug = 0;, which I use to decide whether to echo() some debugging information. When I want to debug some code, I change the value of $debug to 1.

// calculate the future value
require_once("../../includes/php/vars.php");
$investment = 1000;
$interest_rate = .2;
$years = 10;
$future_value = $investment;
if ($debug) {
  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>");
  }
} else {
    echo("\$debug is false (0)");
}

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