Explanation of variables and data types in PHP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.