![]() | IntegersAn integer is a number of the set Z = {..., -2, -1, 0, 1, 2, ...}. See also: Arbitrary length integer / GMP, Floating point numbers, and Arbitrary precision / BCMath SyntaxIntegers can be specified in decimal (10-based), hexadecimal (16-based) or octal (8-based) notation, optionally preceded by a sign (- or +). If you use the octal notation, you must precede the number with a 0 (zero), to use hexadecimal notation precede the number with 0x. Integer overflowIf you specify a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, if you perform an operation that results in a number beyond the bounds of the integer type, a float will be returned instead.
There is no integer division operator in PHP. 1/2 yields the float 0.5. You can cast the value to an integer to always round it downwards, or you can use the round() function. Converting to integerTo explicitly convert a value to integer, use either the (int) or the (integer) cast. However, in most cases you do not need to use the cast, since a value will be automatically converted if an operator, function or control structure requires an integer argument. You can also convert a value to integer with the function intval(). See also type-juggling. From floating point numbersWhen converting from float to integer, the number will be rounded towards zero. If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31), the result is undefined, since the float hasn't got enough precision to give an exact integer result. No warning, not even a notice will be issued in this case!
From other types
| ![]() | ||||||||