<html> <h2>Demo 8 - Demonstrating Scope</H2> <TABLE border=1 cellspacing=0 cellpadding=5 bgcolor=cornsilk width=90%> <TR><TD><CENTER>Variable Name</TD><TD><CENTER>Where Defined</TD><TD><CENTER>Effect</TD></TR> <TR> <TD>variable 1</TD> <TD>php_demo8.php3 (main)</TD> <TD>Available in <i>php_demo8.inc</i> (main), but not in function <i>demo8_function2()</i></TD> </TR><TR> <TD>variable 2</TD> <TD>php_demo8.php3 (main)</TD> <TD>Variables defined in the $GLOBALS array are available everywhere</TD> </TR><TR> <TD>variable 3</TD> <TD>php_demo8.php3 (main)</TD> <TD>Variable3 is just like variable1, except it is available inside of the function <i>demo8_function2()</i> because it is defined as as globally available inside of the the function.</TD> </TR><TR> <TD>variable 4</TD> <TD><i>demo8_function1()</i> (function)</TD> <TD>Variable4 is not available anywhere but in the function where it was defined because it was not defined as a global.</TD> </TR><TR> <TD>variable 5</TD> <TD><i>demo8_function1()</i> (function)</TD> <TD>Variable5 is available anywhere (where it is declared globally available) because it was defined a global in function <i>demo8_fun ction1()</TD> </TR> </TABLE> <?php function demo8_function1() { global $variable5; $variable4 = "Variable4 is available!"; $variable5 = "Variable5 is available!"; } $variable1 = "Variable1 is available!"; $GLOBALS[variable2] = "Variable2 is available!"; $variable3 = "Variable3 is available!"; include ("php_demo8.inc"); demo8_function1(); demo8_function2(); ?> </html>