I want my function to access an outside variable—from its parent function specifically. However, using the global
keyword sets too broad a scope; I need to limit it. How do I get this code to spit out 'Level 2' instead of 'Level 1'? Do I have to make a class?
<?php
$a = "Level 1";
function first() {
$a = "Level 2";
function second() {
global $a;
echo $a.'<br />';
}
second();
}
first();
//outputs 'Level 1'
?>