Integer type usage analysis _php techniques in PHP

Source: Internet
Author: User
The integer can be 10, 8, and 16.
When used in octal, the number needs to start at 0 (0);
When represented in hexadecimal, the number needs to begin with a 0x (0 x) or 0X (0 capital X);

Integer overflow: When an integer overflows, it is automatically converted to float type. Similarly, if an integer type's result overflows the bounds of the integer type, it is automatically converted to a float type.
One thing to note is that the integer type does not have a "/" (division) operation, and if you need to get an integral type, you can use functions such as round, or use (int) or (integer) to force the type into an integer.

Convert to Integer:
Convert Boolean to Integer:
1, True always converts to 1;
2, False is always converted to 0;
Float is converted to integer:
1, if the float type value does not exceed the integer boundary value, then the conversion will directly cut off the decimal part directly.
2. If the float type value exceeds the integer boundary value, the result of the conversion is undefined, but almost certainly not the expected result.
The array type is converted to integer:
1, empty array is always converted to 0;
2, non-empty array is always converted to 1;
object is converted to integer:
1, converting the value of type object to integer produces notice information similar to the object of class StdClass could not is converted to int. The result of the conversion is 1;
String into integer:
1. If string begins with a number and contains no characters '. ', ' e ', ' e ', and the value of the number is within the integer range, string is converted to integer.
Copy Code code as follows:

$resource = fopen (' d:/tmp/test.txt ', ' RB ');
Var_dump ($resource, (int) $resource);

2. String can be converted to integer 0 if string is an empty string, or if there are no digits beginning;
3, in other cases string will be converted to float type;
Resources converted to Integer:
1. Converting the value of the resources type to integer will resource the corresponding ID
For example:

The results
Copy Code code as follows:

Resource (3) of type (stream) int (3)

Null conversion to Integer:
1, NULL conversion to Integer is always 0
The undefined variable is converted to an integer:
1, undefined variable conversion to integer will produce a notice information, and converted to 0

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.