Data type, Number type
Data type
There are three types of data in PHP: Scalar data type, composite data type, special data type
In PHP, a weak data type language, a variable in PHP can store any type of data. The variable type is determined by the data.
Strong data type language:
The strong data type language is characterized by the fact that a variable must be declared to be a variable of this type, based on the type of data that the variable is about to store, before it can be used.
Java Example:
Define a variable to store integer data
int v1 = 100
V1 = ' one '//Immediate error
PHP Weak data type language:
Features, variables can store arbitrary data types.
PHP Example:
Define a variable to store integer data
$v 1 = 100;
$v 1 = ' one ';
Scalar data types
integral type (int, integer)
The value of an integral type is the collection (..... -2,-1,0,1,2,3 ...) A value in the.
Integer takes up 4 bytes (4 means not 4 bits in decimal, but 32 bits in binary)
Maximum representation range for integer type: 2147483647
Principle:
(01111111111111111111111111111111) 2 = (2147483647) 10
The value of an integral type can also be octal, hexadecimal
Octal: Starting with 0, numbers cannot be greater than 7
Hex: Starting with 0x, digital contains 0 to 9, A (10), B, C, D, E, F (15)
Example:
You can use the printf () function to format output data
Grammar:
printf (' format string ', data list)
Description
The format string can contain some placeholders:
%d decimal
%b binary
%o Octal
%x Hex
Example 1:
Example 2:
Decimal type (float)
The number with the decimal point is the decimal type (also known as the precision type), PHP for the decimal type is divided 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-byte (32 bits) maximum representation 2147483647
Float 4 bytes (32 x bits) 3.402823466E+38
IEEE Organizational provisions (Institude electrical electroncity Engineer)
Constraints on floating-point numbers:
0 0000 0 0000 0000 0000 0000 0000
0sign symbol bit 1 bit 0 indicates positive number 1 indicates negative number
0000 0 exponent digit 8 digits
0000 0000 0000 0000 0000 Valid Data bits Mantisa 23-bit
Both the digit and the valid data bits are 0 to represent the data 0, as follows:
0000 0 0000 0000 0000 0000 0000
The number of digits is 1, and the valid data bits are 0, which means the data is infinitely large, as follows:
111 1111 1 0000 0000 0000 0000 0000
The digits are 1, and the valid data bits are nonzero for data null, as follows:
111 1111 1 0000 0000 0000 0000 0000
Range of data represented: determined by index bit and valid data bit
Decimal point:
11111110 254 minus 127 127.
2 of 127-way decimal number = 1.7014118346046923e+38
Valid data bits:
There is a hidden 1 before the valid data bits
000 0000 0000 0000 0000 0000
1.11111111111111111111111 decimal number =>1.99999999999 (approximately equal to 2)
The digits are multiplied by the valid data bits:
1.7014118346046923e+38*2 approximately equal to 3.402823466E+38
Example:
Boolean Boolean type:
It is mainly used to denote the existence of two states of things, right, wrong, true or false.
Value:
True indicates that the setting
False indicates not valid
The value of a Boolean type has no meaning in itself, and is primarily used for process control.
String
A collection of 0 or more characters
How characters are defined:
Method 1:
string defined using single quotation marks
Method 2: Use double quotation marks to define a string
Method 3: Bound string
Grammar:
$v 1 = <<<>< p=""><>
Content
End of delimiter;
Example:
Attention:
The start tag of the delimiter is identical to the closing tag
Cannot have spaces before closing tags
The delimiter can be interpreted as an HTML editor.
Delimiters can be divided into two categories: Heredoc and Nowdoc
Syntax for Heredoc:
Grammar:
$v 1 = <<<>< p=""><>
Content
End of delimiter;
Syntax for Nowdoc:
Grammar:
$v 1 = <<< ' delimiter start '
Content
End of delimiter;
Example:
Attention:
The use of single and double quotation marks, generally if the string does not have a variable using single quotation marks (high efficiency).
Composite data types
Array (arrays)
Arrays are primarily used for storage, with a number of relational data (variables)
Example:
Object (objects) PHP advanced
Special Data Data types:
Resource (Resource type)
The resource type also amounts to a special variable, the programmer cannot do anything to the resource type, only view (Var_dump),
The resource type can only be created by the special function PHP provides for us.
Resource types are primarily used to represent PHP's extended resources (data other than PHP), such as a data connection, a data table result set, an external text file, and so on.
Null (empty)
Null is also a special variable in PHP, representing NULL, generally looking at an undefined variable, or the variable being unset ().
http://www.bkjia.com/PHPjc/1116376.html www.bkjia.com true http://www.bkjia.com/PHPjc/1116376.html techarticle data type, numeric type data type There are three data types in PHP: Scalar data type, composite data type, special data type a weak data type language in PHP, one of PHP ...