I am having some issues with setting a global array in php. The data I get from $_POST is straight from my database. I sent it through an external page to JSON decode/etc. (that part works, so I didnt paste the code). I only want to do this if data is set, then I want to take that array and do other things with it throughout the rest of my code. The problem I am having is the array outside of the if statement is null. I can't seem to figure out why? If I were to echo a var_dump inside the if statement, the values are inside the GLOBALS['Array']
function is_assoc($array) {
foreach (array_keys($array) as $k => $v) {
if ($k !== $v)
return true;
}
return false;
}
$GLOBALS['Array'] = array();
if (isset($_POST['data'])) {
$Data = $_POST['data'];
$decode = new JSONdecoder($Data);
$decode->decodeNew($Data);
$Data = $decode->decodedArray;
$decryptor = new DataDecryptor(base64_decode($_POST['key']), $_POST['tracking'], $hostName);
$decodedData = $decryptor->decrypt_arr($Data);
foreach($decodedData as $key => $val){
if(is_assoc($val)){
foreach($val as $key2 => $val2){
$theArray[$key2] = $val2;
}
}else{
$theArray[$key] = $val;
}
}
$GLOBALS['Array'] = $theArray;
}
echo var_Dump($Array);