Using the analysis _php Tutorial for integer types in PHP

Source: Internet
Author: User
Integer can have 10 binary, 8 binary, 16 binary representation.
In octal notation, the number needs to start at 0 (0);
In hexadecimal notation, the number needs to be 0x (0 x) or 0X (0 caps X) to begin with;

Integer overflow: When an integer overflows, it is automatically converted to the float type. Similarly, if the result of an integer type of operation overflows the bounds of the integer type, it is automatically converted to the 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 directly use (int) or (integer) to force the type to be converted to an integer line.

Convert to Integer:
Boolean converted to Integer:
1, true is always converted to 1;
2, False is always converted to 0;
Float into an integer:
1, if the float type value does not exceed the integer boundary value, then the conversion will directly cut off the fractional 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 an 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 a value of type object to an integer produces a notice information similar to the object of class StdClass could not being converted to int. The result of the conversion is 1;
Convert String to Integer:
1. If string starts with a number and does not contain the character '. ', ' e ', ' e ', and the value of the number 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. String can be converted to integer 0 if string is an empty string, or if no number begins.
3, in other cases, the 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 CodeThe code is as follows:
Resource (3) of type (stream) int (3)

Null is converted to integer:
1, null converted to integer always 0
The undefined variable is converted to an integer:
1. Converting an undefined variable to an integer generates a notice message and converts it to 0

http://www.bkjia.com/PHPjc/322190.html www.bkjia.com true http://www.bkjia.com/PHPjc/322190.html techarticle integer can have 10 binary, 8 binary, 16 binary representation. In octal notation, the number needs to start at 0 (0), and in hexadecimal notation, the number needs to be 0x (0 x) or ...

  • Related Article

    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.