开发者

accessing php variables across files

开发者 https://www.devze.com 2023-03-03 08:50 出处:网络
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 manipulatio

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).

0

精彩评论

暂无评论...
验证码 换一张
取 消