hELLO:
Question 1:
Is it possible to access a variable which is defined in a function with values and 'global' statement. My test turn out to be not. But why, since a variable defined with 'global' statement in function can have outside values.
example 1:
function fun1()
{
$var = "hello";
global $var;
}
echo $var; // fails
example 2:
$var = "hello";
function fun1()
{
global $var;
echo $var;
}
fun1(); //normal, it's ok.
Question 2:
The variable defined with $GLOBALS in a function can be accessed from a script, but can't access from other functions, but can access by $GLOBALS[var] in function.
example 1;
function fun1()
{
$var = "hello";
$GLOBALS['var'];
}
echo $var; //ok
function fun2()
{
echo $var; // fails
echo $GLOBALS['var']; // ok
}
Why?