1. Create a variable
<? PHP $num 1 =; $num 2 = 15.5; Echo $num 1+$num 2; Echo "<br>";? >
2.Local and Global Scopes
<?PHP$x= 5;//Global functionmyTest () {$y= 10;//Local Echo"X:$x"; Echo"<br>"; Echo"Y:$y"; Echo"<br>"; } myTest (); Echo"; Echo"X:$x"; Echo"<br>"; Echo"Y:$y";?>3.PHP Global Keywords
<? PHP $c = ten; $d =; function Test () { global$c$d$f; $f $c $d ; } Test (); Echo "$f";? >
4.PHP also stores all global variables in an array named $GLOBALS [index]. The subscript contains the variable name. This array is also accessible within the function and can be used to update global variables directly.
<? PHP $x = 5; $y =; function test4 () { $GLOBALS$GLOBALS$GLOBALS[' x ']; } Test4 (); Echo "$y";? >
5.PHP Static Keywords
Typically, all variables are deleted when the function finishes/executes. However, sometimes I need to not delete a local variable. Achieving this requires a bit of further work. To do this, use the static keyword when you first declare a variable:
<? PHP function myTest () { static$x=0; Echo $x ; $x+ +; } MyTest (); MyTest (); MyTest ();? >
PHP Basic 02: Variables