diff options
Diffstat (limited to 'scope.php')
-rw-r--r-- | scope.php | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/scope.php b/scope.php new file mode 100644 index 0000000..fc25ce4 --- /dev/null +++ b/scope.php @@ -0,0 +1,50 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>Hacker's Corner</title>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+</head>
+<body>
+<?php
+ $var = 1;
+
+ function test1()
+ {
+ /* local var */
+ $var = 2;
+ echo $var . "<br />\n";
+ }
+
+ function test2()
+ {
+ global $var; /* extern */
+ $var = 2; /* now we actually change the global */
+ echo $var . "<br />\n";
+ }
+
+ function test3()
+ {
+ /* local var with ability to retain value in multiple calls */
+ static $var = 0;
+
+ echo "test3 var: {$var}<br />\n";
+ $var++;
+ }
+
+ test1();
+ echo $var . "<br /><br />\n";
+
+ test2();
+ echo $var . "<br />\n";
+
+ test3();
+ test3();
+ test3();
+ test3();
+ test3();
+ echo $var;
+?>
+</body>
+</html>
+
|