shripati007
shripati007

Reputation: 87

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 value for the array variable in second file for further processing.Any help in this regard will be highly appreciated.

Upvotes: 0

Views: 1234

Answers (2)

Joshua - Pendo
Joshua - Pendo

Reputation: 4371

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

Upvotes: 0

itsols
itsols

Reputation: 5582

Don't use a global variable. Rather, assign the variable to a session before moving on to the next page.

Eg:

$_SESSION["MyArray"] = $MyArrayVariable;

Upvotes: 3

Related Questions