<html>
<body bgcolor=lightyellow>
<H1 Align=center>Variable Scope</h1>
<?php
error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE); //all except warnings & notices
$outerNum1 = 100; //variable defined outside of any functions
$outerNum2 = 150;
print "<b>Outside the function</b><br>";
print "outerNum1: $outerNum1 <br>"; //prints 100
print "outerNum2: $outerNum2 <br>"; //prints 150
print "<br>";
scopeTest( );
//========================================================================
function scopeTest( )
{
global $outerNum1; // makes $outerNum a global variable
global $innerNum1; // makes $innerNum1 a global variable
$innerNum1 = 200; // variable defined inside of a function
$innerNum2 = 250;
print "<b>Inside the function</b><br>";
print "outerNum1: $outerNum1 <br>"; //prints 100
print "outerNum2: $outerNum2 <br>"; //prints null - it is assumed a new variable
print "innerNum1: $innerNum1 <br>"; //prints 200
print "innerNum2: $innerNum2 <br>"; //prints 250
print "<br>";
}
//========================================================================
print "<b>Outside the function</b><br>";
print "outerNum1: $outerNum1 <br>"; //prints 100
print "outerNum2: $outerNum2 <br>"; //prints 150
print "innerNum1: $innerNum1 <br>"; //prints 200
print "innerNum2: $innerNum2 <br>"; //prints null - it is assumed a new variable
?>
<?php include "../include.php"; ?> <!-- hyperlink to see the code -->
</body>
</html>