Integer can be in decimal, octal, or hexadecimal format.
In octal notation, the number must start with 0 (0;
In hexadecimal notation, the number must begin with 0x (Zero x) or 0X (Zero capital X;
Integer Overflow: When an integer overflows, it is automatically converted to the float type. Similarly, if the integer Operation Result overflows the integer boundary, it is automatically converted to the float type.
Note that the integer type does not have a "/" (Division) operation. To obtain an integer, you can use functions such as round, or directly use (int) or (integer) to convert the data type to integer.
Convert to integer:
Boolean to integer:
1. true is always converted to 1;
2. false is always converted to 0;
Float to integer:
1. If the float type value does not exceed the integer boundary value, the fractional part is directly truncated during conversion.
2. If the float type value exceeds the integer boundary value, the conversion result is not defined, but it is almost certainly not the expected result.
Array type conversion to integer:
1. Empty array is always converted to 0;
2. Non-empty array is always converted to 1;
Object conversion to integer:
1. converting an object type value to an integer will generate Notice information similar to Object of class stdClass cocould not be converted to int. The conversion result is 1;
String to integer:
1. If the string starts with a number and does not contain the characters '.', 'E', and 'E', and the value of the number is within the integer Range, the string is converted to an integer.
Copy codeThe Code is as follows:
$ Resource = fopen ('d:/tmp/test.txt ', 'rb ');
Var_dump ($ resource, (int) $ resource );
2. If the string is a null string or does not start with a number, the string can be converted to integer 0;
3. In other cases, the string type will be converted to the float type;
Resources to integer:
1. to convert the value of the resources type to integer, the corresponding id of the resource will be
For example:
Result
Copy codeThe Code is as follows:
Resource (3) of type (stream) int (3)
Convert null to integer:
1. Converting null to integer is always 0
Undefined variables are converted to integer:
1. If an undefined variable is converted to an integer, a notice information is generated and converted to 0.