Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

PHP Integers

Examples of integers include 2, 256, -256, 10358, and -179567.

An integer is a number without any decimal part.

In 32-bit systems, the integer data type represents non-decimal numbers between -2147483648 and 2147483647. In 64-bit systems, it represents numbers between -9223372036854775808 and 9223372036854775807. Values outside these ranges will be stored as floats because they exceed the limits of an integer.

Note: It’s important to know that even if the result of 4 * 2.5 is 10, it will be stored as a float because one of the operands (2.5) is a float.

Here are some rules for integers:

  • An integer must contain at least one digit.
  • An integer cannot have a decimal point.
  • An integer can be either positive or negative.
  • Integers can be represented in four formats: decimal (base 10), hexadecimal (base 16, prefixed with 0x), octal (base 8, prefixed with 0), or binary (base 2, prefixed with 0b).

PHP has the following predefined constants for integers:

  • PHP_INT_MAX: The largest supported integer.
  • PHP_INT_MIN: The smallest supported integer.
  • PHP_INT_SIZE: The size of an integer in bytes.

PHP provides the following functions to check if a variable is of integer type

  • is_int()
  • is_integer() (alias of is_int())
  • is_long() (alias of is_int())

Example

Verify if a variable is of integer type:

$x = 5985;
var_dump(is_int($x));
$x = 59.85;
var_dump(is_int($x));