Php Integer)

Source: Internet
Author: User
The integer value can be in decimal, hexadecimal, octal, or binary format. an optional symbol (-or +) can be added before ). Integer expressed in binary format is available from PHP5.4.0. An integer is a number in the set period = {...,-2,-1, 0, 1, 2.

Syntax

The integer value can be in decimal, hexadecimal, octal, or binary format. an optional symbol (-or +) can be added before ).

Integer expressed in binary format is available in PHP 5.4.0.

To use the octal expression, add 0 (zero) before the number ). To use a hexadecimal expression, you must add 0x before the number. To use a binary expression, you must add 0 B before the number.

Example #1 integer text expression

` `

The formal description of integer is:

Decimal: [1-9] [0-9] *
| 0

Octal: 0 [0-7] +

Binary: 0b [01] +

Integer: [+-]? Decimal
| [+-]? Octal
| [+-]? Binary

The length of the integer is related to the platform, although the maximum value is usually about 2 billion (32-bit signed ). The maximum value of a 64-bit platform is usually about 9E18. PHP does not support unsigned integers. The length of the Integer value can be expressed by the constant PHP_INT_SIZE. after PHP 4.4.0 and PHP 5.0.5, the maximum value can be expressed by the constant PHP_INT_MAX.

Warning

If an invalid number (8 or 9) is passed to the octal number, the remaining digits are ignored.

Example #2 strange things about the eight-digit number

` `

Integer overflow

If a given number exceeds the integer range, it is interpreted as float. Similarly, if the execution result exceeds the integer range, float is returned.

Example #3 integer overflow in 32-bit systems

` `

Example #4 integer overflow in 64-bit systems

` `

PHP does not have the division operator. 1/2 generates float 0.5. The value can be forcibly converted to integer by dropping the decimal part, or the round () function can be used to better rounding.

` `

Convert to integer

To explicitly convert a value to an integer, use (int) or (integer) to force the conversion. However, in most cases, no forced conversion is required, because the value is automatically converted when an integer parameter is required for the operator, function, or flow control. You can also convert a value to an integer using the intval () function.

See: identify type conversion.

Convert from Boolean

FALSE will generate 0 (zero), and TRUE will generate 1 (one ).

From floating point type conversion

When the value is converted from a floating point to an integer, the value is rounded down.

If the floating point number exceeds the integer range (+/-2.15e + 9 = 2 ^ 31,64-bit platforms are usually +/-9.22e + 18 = 2 ^ 63 ), the result is undefined because there is not enough precision to give an exact integer result. In this case, there is no warning or even no notification!

Warning

Never forcibly convert an unknown score to an integer, which sometimes leads to unexpected results.

` `

Convert from string

Convert from other types

Caution

The conversion from other types to integer type is not defined. Do not rely on any existing behavior because it will change without notice.

Related Keywords:

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.