This article mainly share with you some basic knowledge of PHP, PHP variables and data types to explain, I hope to help everyone.
1. What is a variable
The variable is the equivalent of a pocket that can store things inside.
In programming languages, variables are used to store values.
2. How PHP declares variables
Through "$"
You can also not declare the use of variables; (Bad habits)
You can declare one or more
Precautions
The variable name starts with a letter or underscore, followed by a number, a letter underline;
Variable names are best meant to be clear
It is best to follow the hump marking method and underline method
Variable names are strictly case-sensitive
The variable is declared repeatedly, and later overrides the previous
Variable variable
The principle is equal substitution, see the following example:
$i = ' j '; $j = ' k '; $k = ' Hello World '; Echo $$ $i; $$ $i, $ $j-$k
The final output is Hello World
Data type
Eight main types:
Scalar type (only single data can be stored)
Integer type (int)
Classification:
Decimal, 16 binary, octal
Range:
With minus sign-2.1 billion ~21 billion
With no 4.2 billion
Out of storage range, overflow occurs
Floating-point type (floatdouble)
Classification:
With a decimal point, with E or E
Attention:
Floating-point numbers are error-not to compare the size of floating-point values!!!
Boolean Type (Boolean)
true | False
String type (Strings)
Delimiter
The difference between single and double quotation marks
The single quotation mark does not parse the variable, the execution efficiency is high;
Single quotation marks only parse \ ' and \ \ These two escape characters
Heredoc
When writing large pieces of content, use the equivalent of double quotation marks.
How to use:
<<< Custom Names
Code snippet .....
Custom name;
Special attention:
In the line of the custom name of the Terminator, the front cannot have any characters.
Nowedoc
The equivalent of single quotation marks, compared to Heredoc, only at the beginning, the custom name needs to be wrapped in single quotation marks.
Composite type
Array
Object
Special types
Resources (Resource)
Empty (Null | NULL)
1. The variable is not declared to be used directly, its value is null
2. Declare a variable and assign a value of NULL
3. A variable that has been unset () is cancelled, and the value is null
Variable
1. What is a variable
The variable is the equivalent of a pocket that can store things inside.
In programming languages, variables are used to store values.
2. How PHP declares variables
Through "$"
You can also not declare the use of variables; (Bad habits)
You can declare one or more
Precautions
The variable name starts with a letter or underscore, followed by a number, a letter underline;
Variable names are best meant to be clear
It is best to follow the hump marking method and underline method
Variable names are strictly case-sensitive
The variable is declared repeatedly, and later overrides the previous
Variable variable
The principle is equal substitution, see the following example:
$i = ' j '; $j = ' k '; $k = ' Hello World '; Echo $$ $i; $$ $i, $ $j-$k
The final output is Hello World
Data type
Eight main types:
Scalar type (only single data can be stored)
Integer type (int)
Classification:
Decimal, 16 binary, octal
Range:
With minus sign-2.1 billion ~21 billion
With no 4.2 billion
Out of storage range, overflow occurs
Floating-point type (floatdouble)
Classification:
With a decimal point, with E or E
Attention:
Floating-point numbers are error-not to compare the size of floating-point values!!!
Boolean Type (Boolean)
true | False
String type (Strings)
Delimiter
The difference between single and double quotation marks
The single quotation mark does not parse the variable, the execution efficiency is high;
Single quotation marks only parse \ ' and \ \ These two escape characters
Heredoc
When writing large pieces of content, use the equivalent of double quotation marks.
How to use:
<<< Custom Names
Code snippet .....
Custom name;
Special attention:
In the line of the custom name of the Terminator, the front cannot have any characters.
Nowedoc
The equivalent of single quotation marks, compared to Heredoc, only at the beginning, the custom name needs to be wrapped in single quotation marks.
Composite type
Array
Object
Special types
Resources (Resource)
Empty (Null | NULL)
1. The variable is not declared to be used directly, its value is null
2. Declare a variable and assign a value of NULL
3. A variable that has been unset () is cancelled, and the value is null