Variable naming rules

In PHP, variable names must start with a “$” sign;

2. The name contains letters, digits, and underscores (_), but cannot start with a number.

3. Chinese variables are allowed in PHP itself (not recommended).

Predefined variable

Pre-defined variables: pre-defined variables, system defined variables, store a lot of data needed (pre-defined variables are arrays)

  • $_GET: Gets the data submitted by all forms as GET
  • $_POST: Data submitted by POST is saved here
  • $_REQUEST: GET and POST submissions are saved
  • $GLOBALS: all global variables in PHP
  • $_SERVER: indicates server information
  • $_SESSION: indicates session data
  • $_COOKIE: indicates the cookie session data
  • $_ENV: indicates the environment information
  • $_FILES: files uploaded by users

Volatile variables

Variable: If a variable holds a value that is the name of another variable, you can access the value of the other variable directly by adding a $sign in front of the variable.

$a = ‘b’;
$b = ‘bb’;

$$a --> bb
Copy the code

Variables by value

  • To assign a variable to another variable: variable pass
  • There are two ways to pass a variable value: value pass and reference pass
  1. Value passing: To assign a value to a variable and store the new value to another variable (the two variables are unrelated)

  2. Pass by reference: To pass the memory address of the value stored in a variable to another variable: two variables refer to the same memory space (both variables have the same value).
$新变量 = &$老变量;
Copy the code

  • In memory, there are usually the following partition stack areas: the portion of memory the program can operate on (no data, running program code), small but fast code segment: The portion of memory that stores the program (no execution) Data segment: Stores ordinary data (global and static) Heap: stores complex data, large but inefficient

Code implementation: