Home >Backend Development >PHP Tutorial >Local variables and global variables in php_PHP tutorial
How to understand scope in PHP? Let’s introduce local variables: variables declared inside functions. Global variables: Variables declared outside the function should be explained in detail
7.2.8 Convert local variables into global variables
The code is as follows
|
Copy code
|
||||
$a = 5;
|
output
The code is as follows | Copy code |
$GLOBALS['a'] = 5;
function funcChangeValue()
{
$GLOBALS['a'] = 10;
}
funcChangeValue();
echo $GLOBALS['a'];
?> Output 10 http://www.bkjia.com/PHPjc/629235.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629235.htmlTechArticleHow to understand scope in PHP? Let’s introduce local variables: declared inside a function variable. Global variables: variables declared outside the function, detailed description... |