In PHP, variables that are defined in a function, including parameters, cannot access the external variables of the function, and, by default, variables that are defined outside a function cannot be accessed by a variable.
In the PHP tutorial, variables defined in a function, including parameters, cannot access the external variables of the function, and in the default case, variables defined outside a function cannot be accessed by a variable.
See example below
$a = 1;
$b = 2;
function Sum ()
{
Global $a, $b;
$b = $a + $b;
}
Sum ();
Echo $b;
?>
This returns the value of $b to 3, which is a global variable in PHP, so we will now look at the PHP variable reference instance
function Str_unite (& $string)
{
$string. = ' also like blue. ';
}
$str = ' like red, ';
Str_unite ($STR);
Echo $str; Output: ' Like red, also like blue. '
?>
, which is a reference to the global variables and functions of the scope of the function, the following is a local variable of the function
$a = 1;
$b = 2;
function Sum ($a, $b)
{
$b = $a + $b;
echo $b;//3
}
Sum ();//
echo $b;//2
?>
This site original tutorial reproduced annotated source www.bkjia.com/phper/php.html
http://www.bkjia.com/PHPjc/445451.html www.bkjia.com true http://www.bkjia.com/PHPjc/445451.html techarticle In PHP, variables defined in a function, including parameters, cannot access the external variables of the function, and in the default case, variables defined outside a function cannot be accessed ...