accessing php variables across files
I have a php file with array as a global variable.I wish that the array should be accessed in other php file for further processing.But the thing is the global array variable is undergoing manipulation by a certain function in the first file.I want the updated开发者_如何学JAVA value for the array variable in second file for further processing.Any help in this regard will be highly appreciated.
Don't use a global variable. Rather, assign the variable to a session before moving on to the next page.
Eg:
$_SESSION["MyArray"] = $MyArrayVariable;
You could add everything inside a $_SESSION variabel, I'm not sure what filestructure you use:
include('file1.php');
include('file2.php');
or a setup where you from file1.php to file2.php.
In the first setup, you can get the settings outside a function/class and then they are available in file2. In the second you have to store them somewhere (cookie, session, database).
精彩评论