\$debug = $debug

"); ?>

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

"); 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 . "
"); } } else { echo("\$debug is false (0)"); } ?>

Back