So I have the following 3 files:
index.php
<?php
require("require/functions.php");
$g = getGroup();
var_dump($data);
die();
?>
functions.php
<?php
function getGroup(){
if(condition) $g = 1;
else if(another condition) $g = 2;
else if...etc
require("data/$g.php");
return $g;
}
?>
An example e.g. data/1.php file:
<?php
$data = ["Some random data"];
?>
I tried various approaches like using global $data
in index.php
and various other things, but didn't have any luck using this approach
I could do it by changing the getGroup()
function to getGroupAndData()
and returning [$g, $data]
, however that isn't really ideal...
Likewise I also created a global variable $temp
in functions.php
, used $temp = $data
, then could use global $temp
in the index.php
file
My current preferred method is just to use $GLOBALS['data'] = $data
inside the getGroup()
, function, though I'm curious, is there anyway I can access this $data
array from within the index.php
file without having to use these workarounds?
Thanks