I’m trying to store an array in a PHP GLOBAL like so:
// file_1.php
include 'functions/session_metrics.php';
$project_data = array();
$session_data = array();
if (isset($_GET["product"])) {
$product = explode("|", $_GET["product"]);
foreach ($product as $id) {
list($project, $sessions) = getProductInfo( $id );
$project_data[$id] = $project;
$session_data[$id] = $sessions;
}
$GLOBALS['project_data'] = $project_data;
$GLOBALS['session_data'] = $session_data;
}
Now from another file I’m trying to retireve it like so:
// file_2.php
$data= $GLOBALS['project_data'];
print_r($data);
But I see the error:
Undefined Index: project_data...
What am I missing?
Why not just use native php
$_SESSIONto store session data:Also by doing this:
$GLOBALS['session_data'] = $session_data;you are setting a value equal to itself (which is implicit) unless$session_datais inside of a function.