I looked around but can't really find anything. I tried using global but I think I am using it wrong.
function testing() { $a = (object) array('a' => 100, 'b' => 200); function test2(){ global $a; var_dump($a); } test2(); } testing(); I want to be able to get $a inside test2() without passing the variable as parameter.
EDIT: Thank you for the comments and answers. The examples work however in my specific case it does not seem to work. I wrote this little function at the top of my view, then call it when I need it.
var_dump($data); // DATA here is fine - I need it in the function function getDataVal($data_index) { return (isset($data->{$data_index}))?$data->{$data_index}:''; } I then call it on the page a bit later like this:
<input type="text" id="something" value="<?=getDataVal('something')?>" /> I know I can just pass $data in the request, however I was hoping there was an easier way to access data inside that function.