Global_PHP tutorial in php

Source: Internet
Author: User
Php global .? Php $ Ahello; functionprint_a () {$ Aphpmysql; global $ A; $ Amytest; echo $ A;} echo $ A; echobr; print_a (); echobr; echo $ ;? Output result: hellomytestmytest has a point at the beginning.

$ A = "hello ";

Function print_a (){

$ A = "php & mysql ";
Global $;
$ A = "mytest ";
Echo $;
}

Echo $;
Echo"
";
Print_a ();
Echo"
";
Echo $;
?>

Output result:

Hello
Mytest
Mytest

At first, I had some doubts. However, this program and the output results clearly explain what is going on in global.

In function definition, after global is declared, the variable is global. of course, even if the function has defined a local variable with the same name, it cannot be used, instead, it is referenced in the previous definition.


From Liujie

Http://www.bkjia.com/PHPjc/478330.htmlwww.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 $ ;? Output result: hello mytest start with a dot...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.