Ask the PHP global variable question? & Nbsp; I declare a global variable $ GLOBALS [& quot; x & quot;] 1; & nbsp; in 1. in php, redefine $ GLOBALS [& quot; x & quot;] 2; & nbsp; in 2. php shows that the result of $ GLOBALS [& quot; x & quot;] is still 1; & nbsp; my idea is to ask the PHP global variable question?
I declare a global variable $ GLOBALS ["x"] = 1;
Redefine $ GLOBALS ["x"] = 2 in 1. php;
In 2.php, the result of $ GLOBALS ["x"] is still 1;
My idea is that there is a global variable. if it is modified, its value will be subject to the newly modified value. I don't know how to deal with it in PHP?
------ Solution --------------------
1. php
Session_start ();
$ _ SESSION ['x'] = 1;
2. php
Session_start ();
$ _ SESSION ['x'] = 2;
3. php
Session_start ();
Echo $ _ SESSION ['x'];
------ Solution --------------------
You use
Global $ x = 1;
Global $ x = 2;
Echo $ x;
Try
Unlike $ GLOBALS ['x '];
------ Solution --------------------
$ GLOBALS ["x"] = 1; // temporary global variable. It is not a global variable in a session. So B. php shows 1
------ Solution --------------------
Global variables are only valid in the same PHP file. sessions are required for different php files.
------ Solution --------------------
Only sessions can access each other on each page!
The variables defined or accessed by gloabl and $ GLOBALS are all variables on this page!
To access variables in other files, you need to load the file!
There is a fundamental difference with session!