FROM PHP Guide :
A warning
If you assign a link to a variable declared global inside the function, the link will only be visible inside the function. You can avoid this by using the $ GLOBALS array.
...
Think of global $ var; as a shortcut to $ var = & $ GLOBALS ['variable'] ;. Thus, assigning another reference to $ var only changes the local variable reference.
<?php $a=array(); $a[]='works'; function myfunc () { global $a, $b ,$c; $b= $a[0]; $c=&$a[0]; $GLOBALS['d'] = &$a[0]; } myfunc(); echo ' $b '.$b."<br>"; //works echo ', $c '.$c."<br>"; //fails echo ', $d '.$d."<br>"; //works ?>
For more information, see Which Links Are Not and Return Links
user1646111
source share