Home  >  Article  >  Backend Development  >  Explanation of variables and data types in php

Explanation of variables and data types in php

小云云
小云云Original
2018-03-27 16:14:321284browse

This article mainly shares with you some basic knowledge of PHP and explains variables and data types in PHP. I hope it can help you.

1. What is a variable?

A variable is equivalent to a pocket that can store things in it.
In programming languages, variables are used to store values.

2. How to declare variables in PHP

Use "$"
You can also use variables without declaring them; (bad habit)
You can declare one or more

## at a time #Notes

The variable name starts with a letter or an underscore, followed by numbers and letters and underscores;

It is best to have a clear meaning of the variable name

It is best to follow the camel case notation method, Underscore method

Variable names are strictly case-sensitive

Repeated declarations of variables will overwrite the previous

Variable variables

The principle is to replace them with equal amounts , please see the following example:

$i = 'j';
$j = 'k';
$k = 'hello world';
echo $$$i;  // $$$i -> $$j -> $k

The final output result is hello world

Data type

Eight main types:

Scalar type (only Store single data)

Integer type (int)

Category:

Decimal, hexadecimal, octal

Range:

With negative sign -2.1 billion~2.1 billion

Without 4.2 billion

Exceeding the storage range, overflow will occur

Floatdouble

Classification :

With decimal point, e or E

Note:

Floating point numbers have errors, do not compare the size of floating point values!!!

boolean

true | false

String type(string)

Delimiter

The difference between single quotes and double quotes

Single quotes do not parse variables, and the execution efficiency is high;

Single quotes only parse the two escape characters \' and \\

heredoc

Write large sections of content When used, it is equivalent to double quotes.

How to use:

<<Code snippet....
Custom name;

Special note:

There cannot be any characters in front of the custom name line of the end character.

nowedoc

is equivalent to single quotes. Compared with heredoc, the custom name needs to be wrapped in single quotes at the beginning.

Composite type

Array

Object

Special type

Resource(Resource)

Empty(null | NULL)

1. The variable is used directly without being declared, and its value is null

2. Declare a variable and assign the value to null

3. Log out after unset() The value of the passed variable is null

Variable

1. What is a variable

A variable is equivalent to a pocket in which things can be stored.

In programming languages, variables are used to store values.

2. How to declare variables in PHP

Use "$"

You can also use variables without declaring them; (bad habit)
You can declare one or more
## at a time #Notes

The variable name starts with a letter or an underscore, followed by numbers and letters and underscores;

It is best to have a clear meaning of the variable name

It is best to follow the camel case notation method, Underscore method

Variable names are strictly case-sensitive

Repeated declarations of variables will overwrite the previous

Variable variables

The principle is to replace them with equal amounts , please see the following example:

$i = &#39;j&#39;;
$j = &#39;k&#39;;
$k = &#39;hello world&#39;;
echo $$$i;  // $$$i -> $$j -> $k

The final output result is hello world

Data type

Eight main types:

Scalar type (only Store single data)

Integer type (int)

Category:

Decimal, hexadecimal, octal

Range:

With negative sign -2.1 billion~2.1 billion

Without 4.2 billion

If it exceeds the storage range, overflow will occur

Floatdouble

Category:

With decimal point, with e or E

Note:

Floating point numbers have errors, do not compare the size of floating point values!!!

Boolean

true | false

String type(string)

Delimiter

Single quotes and double quotes Difference

Single quotes do not parse variables, and the execution efficiency is high;

Single quotes only parse the two escape characters \' and \\

heredoc

Write in upper letters Used when describing paragraph content, equivalent to double quotes.


How to use:

<<Code snippet....

Custom name;


Special note:

There cannot be any characters in front of the custom name line of the end character.


nowedoc

is equivalent to single quotes. Compared with heredoc, the custom name needs to be wrapped in single quotes at the beginning.


Composite type

Array

Object

Special type

Resource(Resource)

Empty(null | NULL)

1. The variable is used directly without being declared, and its value is null

2. Declare a variable and assign the value to null

3. Log out after unset() The variable passed has a value of null

Related recommendations:

Example analysis of variables and constants in PHP

Naming rules for variables in PHP Detailed explanation

A brief discussion on the data type judgment function example code of variables in PHP

The above is the detailed content of Explanation of variables and data types in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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