Home > Backend Development > PHP Tutorial > php global_PHP tutorial

php global_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:49:47
Original
765 people have browsed it

$A="hello";

function print_a(){

$A="php&mysql";
global $A;
$A="mytest";
echo $A;
}

echo $A;
echo "
";
print_a();
echo "
";
echo $A;
?>

Output result:

hello
mytest
mytest

I was a little confused at first, but this program and the output clearly illustrate what global.

In the function definition, after declaring global, the variable becomes global. Of course, even if a local variable with the same name has been defined in the function, "it" is no longer used, and it becomes a reference to the previously defined variable. .


Excerpted from Liu Chuan

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478330.htmlTechArticle?php $A=hello; function print_a(){ $A=phpmysql; global $A; $A= mytest; echo $A; } echo $A; echo br; print_a(); echo br; echo $A; ? Output result: hello mytest mytest There is a little bit at the beginning...
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template