Table of Contents
What is the meaning of global array in php
Home Backend Development PHP Problem What does global array mean in php

What does global array mean in php

Sep 20, 2022 pm 05:15 PM
php

The full name of global data in PHP is superglobal array or superglobal variable, which is a specially defined array variable in PHP; superglobal array can be accessed anywhere in the script and in any scope, superglobal Array variables are built-in variables that are always available in all scopes.

What does global array mean in php

The operating environment of this article: Windows 10 system, PHP version 8.1, Dell G3 computer

What is the meaning of global array in php

php The full name of the global array is "super global array" or "super global variable". It is a specially defined array variable in PHP. It is called super global array because these arrays can be used anywhere in the script and in any scope. Access, such as functions, classes, files, etc.

Super global array variables are built-in variables that are always available in all scopes

Super global arrays in PHP include the following:

  • $GLOBALS

A global combined array containing all variables. The name of the variable is the key of the array.

Use var_dump($GLOBALS) to print, you can see that $GLOBALS is a global combination array that contains all.

As of PHP 8.1.0, $GLOBALS is now a read-only copy of the global symbol table. That is, global variables cannot be modified through copies. In previous versions, $GLOBALS arrays and PHP arrays generally behaved differently when passing values, and global variables could be modified via copies.

Before PHP 8.1.0:

$a = 1;$globals = $GLOBALS; // 表面意义的按值复制$globals['a'] = 2;   // $GLOBALS['a'] 的值也相应修改
var_dump($a);//运行结果:
int(2)
Copy after login

From PHP 8.1.0:

$a = 1;$globals = $GLOBALS;    //表面意义的按值复制$globals['a'] = 2;    // $GLOBALS['a'] 的值不会改变(不再修改 $a)
var_dump($a);//运行结果:
int(1)
Copy after login

To restore the previous behavior, iterate over its copy and assign each property back $GLOBALS:

foreach ($globals as $key => $value) {
    $GLOBALS[$key] = $value;}
Copy after login
  • $_SERVER

$_SERVER - Server and execution environment information. $_SERVER is an array containing information such as header, path, and script locations. The items in this array are created by the web server.

  • $_GET

An array of variables passed to the current script via URL parameters. Note: This array is not only effective for requests whose method is GET, but for all requests with query string.

  • $_POST

The predefined $_POST variable is used to collect data from forms with method="post" value.

When the Content-Type of the HTTP POST request is application/x-www-form-urlencoded or multipart/form-data, the variables will be passed into the current script in the form of an associative array.

Information sent from a form with the POST method is invisible to anyone (will not be displayed in the browser's address bar), and there is no limit on the amount of information sent.
Note: However, by default, the maximum amount of information sent by the POST method is 8 MB (can be changed by setting post_max_size in the php.ini file).

  • $_REQUEST

Contains an array of $_GET, $_POST and $_COOKIE by default. Due to security issues, it is recommended to avoid using $_REQUEST.

  • $_COOKIE

An array of variables passed to the current script through HTTP Cookies.

  • $_SESSION

An array of SESSION variables available to the current script.

  • $_FILES

An array of projects uploaded to the current script via HTTP POST.

  • $_ENV

An array of variables passed to the current script through the environment.

These variables are imported from the PHP parser's running environment into the PHP global namespace. Many are provided by shells that support PHP running, and different systems are likely to run different kinds of shells, so a definitive list is impossible. Please check your shell documentation for a list of defined environment variables.

Other environment variables include CGI variables, regardless of whether PHP is running as a server module or a CGI processor.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What does global array mean in php. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles