Question
why the unset function is different between global and $GLOBALS ?
here is my code , the $GLOBALS
version will echo nothing ,but the global
will echo "hi".
//$GLOBALS version
<?php
function foo()
{
unset($GLOBALS['bar']);
}
$bar ="hi";
foo();
echo $bar;
?>
the code above echo nothing
but when i change $GLOBALS['bar']
to global $bar
,it echo "hi"
//global version
<?php
function foo()
{
global $bar;
unset($bar);
}
$bar = "hi";
foo();
echo $bar;
?>
I have search in google and php manual , but it seems not detail about this problem . what is the difference between GLOBALS and GLOBAL?