What is the usage of $GLOBALS in php

王林
Release: 2023-03-10 13:10:01
Original
3091 people have browsed it

The usage of $GLOBALS in php is to reference all variables available in the global scope, such as [$GLOBALS["foo"]]. $GLOBALS is a global combined array containing all variables.

What is the usage of $GLOBALS in php

The operating environment of this article: windows10 system, php 7.3, thinkpad t480 computer.

$GLOBALS is used to reference all variables available in the global scope. It is a global combined array containing all variables. The name of the variable is the key of the array.

Example:

<?php
function test() {
    $foo = "local variable";

    echo &#39;$foo in global scope: &#39; . $GLOBALS["foo"] . "\n";
    echo &#39;$foo in current scope: &#39; . $foo . "\n";
}

$foo = "Example content";
test();
?>
Copy after login

The output of the above routine is similar to:

$foo in global scope: Example content
$foo in current scope: local variable
Copy after login

Related video sharing: php video tutorial

The above is the detailed content of What is the usage of $GLOBALS in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template