Data type, numeric type. Data type, numeric data type PHP has three data types: scalar data type, composite data type, special data type PHP weak data type language, a data type in php, numeric type
Data type
PHP has three data types: scalar data type, composite data type, and special data type.
A weak data type language in PHP. a variable in php can store any type of data. The variable type is determined by the data.
Strong data type language:
A strong data type language is characterized by declaring a variable of this type based on the type of the data to be stored in the variable before using a variable.
Java example:
Define a variable to store integer data
Int v1 = 100
V1 = 'one' // An error is reported immediately.
PHP weak data type language:
Feature, variables can store any data type.
Php example:
Define a variable to store integer data
$ V1 = 100;
$ V1 = 'one ';
Integer (int, integer) of the scalar data type)
The integer value is a value in the set (...-2,-, 3.
Integer occupies four bytes (4 indicates not four digits in decimal format, but 32 digits in binary format)
The maximum integer value range is 2147483647.
Principle:
(01111111111111111111111111111111) 2 = (2147483647) 10
The integer value can also be octal or hexadecimal.
Octal: starts with 0, and the number cannot exceed 7
Hexadecimal: It starts with 0x. the numbers include 0 to 9, A (10), B, C, D, E, and F (15)
Example:
You can use the printf () function to format the output data.
Syntax:
Printf ('formatted string', data list)
Note:
The format string can contain some placeholders:
% D decimal
% B binary
% O octal
% X hexadecimal
Example 1:
Example 2:
Float)
The number of decimal points is the decimal point type (also called the precision type). PHP divides the decimal point type into single precision (float \ single) and double precision (double)
Float type
Double type
Type |
Bytes |
Minimum value |
Maximum value |
Float |
4 |
-3.402823466E + 38 |
3.402823466E + 38 |
Double |
8 |
-1. 7976931348623157e + 308 |
1.7976931348623157E + 308 |
Integer 4 bytes (32 binary digits) up to 2147483647
Float 4 bytes (32 binary bits) 3.402823466E + 38
IEEE organization rules (instancelectrical Electroncity Engineer)
Floating point number constraints:
0000 0000 0000 0000 0000 0000 0000
0 sign 1 bit 0 indicates positive number 1 indicates negative number
000 0000 0 exponent index bit has 8 digits
000 0000 0000 0000 0000 0000 valid data bit Mantisa 23-bit
Both the index bit and valid data bit 0 indicate data 0, as shown below:
000 0000 0000 0000 0000 0000 0000
The exponent bits are both 1 and the valid bits are all 0, which indicates that the data is infinite, as shown below:
111 1111 1000 0000 0000 0000 0000
The index bits are both 1, and valid data bits are both non-zero, indicating that the data is null, as shown below:
111 1111 1000 0000 0000 0000 0000
Data range: Determined by the exponent and valid data bit.
Index bit:
11111110 254 minus 127 127
The second decimal number of 2 => 1.7014118346046923e + 38
Valid data bit:
There is a hidden 1 before the valid data bit
0000 0000 0000 0000 0000
1.11111111111111111111111 decimal number => 1.99999999999 (approximately 2)
Multiply the index bit by the valid data bit:
1.7014118346046923e + 38*2 approximately equal to 3.402823466E + 38
Example:
Boolean type:
It is mainly used to indicate the only two states of a thing.
Valid value:
True indicates true.
False indicates invalid
Boolean values are meaningless and mainly used for process control.
String
A set of 0 or more characters.
Character definition:
Method 1:
String defined using single quotes
Method 2: Use a string defined by double quotation marks
Method 3: define a string
Syntax:
$ V1 = < <定界符开始< p>
Content
The separator ends;
Example:
Note:
The start mark and end mark of the delimiter must be consistent.
No space before the end mark
The delimiters can be understood as html editors.
There are two types of delimiters: heredoc and nowdoc.
Heredoc syntax:
Syntax:
$ V1 = < <定界符开始< p>
Content
The separator ends;
Nowdoc syntax:
Syntax:
$ V1 = <'delimiter start'
Content
The separator ends;
Example:
Note:
Use of single quotes and double quotes. generally, if the string does not have any variable, use single quotes (high efficiency ).
Composite data type
Array)
Arrays are mainly used for storage. multiple data with certain relationships (variables)
Example:
Object PHP advanced
Special data type: resource)
The resource type also contains a special variable. the programmer cannot perform any operations on the resource type, but can only view (var_dump ),
Resource types can only be created using special functions provided by PHP.
Resource types are mainly used to represent php Extension Resources (data outside PHP), such as a data connection, a data table result set, and an external text file.
Null)
Null is also a special variable in PHP, which indicates null. Generally, you can view an unspecified variable or the variable is unset ().
Data type PHP has three data types: scalar data type, composite data type, special data type PHP weak data type language, one in php...