PHP - variables

Table of contents

variable declaration

variable release

variable naming

Variable assignment and initialization

mutable variable

variable reference assignment

variable declaration

One of the features of PHP is that it does not require variables to be declared before they are used . A variable is created when it is assigned a value for the first time . Variables are used to store values ​​such as numbers, text strings, or arrays. Once a variable is set, it can be reused in scripts.

Variables in PHP must be represented by a dollar sign $ followed by the variable name , using the assignment operation = to assign a value to a variable.

<?PHP
echo $name; //变量未定义,内存中没有创建该变量
$name = "HYC";  //变量的初始化赋值,会在内存中创建该变量
echo $name;  //HYC
?>

variable release

The unset() function releases the specified variable

unset($name); //release $name

variable naming

1. Variable names are strictly case-sensitive, and variables with different case are completely different.

2. The variable name is composed of letters, numbers, and underscores, and cannot start with a number, nor can it contain other characters (blank characters...)

3. Adopt camel case naming method

4. It is not recommended to use keywords as variable names

Variable assignment and initialization

When a variable is used for the first time, it is assigned a value. This process is called "initialization". When the variable is used later, the value of the variable can be modified at any time.

Directly use a = to complete the assignment of variables.

That is, it can be used directly by assigning a value to the variable.

mutable variable

A variable name can be dynamically set and used.

$$ is a feature of PHP, and it is also the cause of variable coverage vulnerabilities in PHP.

<?php
$name = "HYC";
$$name = "hello word"; //$ABC
echo $name;
echo "<hr />";
echo $ABC;
?>

The final output is: HYC hello word 

variable reference assignment

Simply understood as an alias for the variable

$b=$a;

 

Guess you like

Origin blog.csdn.net/heyingcheng/article/details/129556558