> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PHP int

An `int` (integer) in PHP is a scalar data type representing a whole number belonging to the mathematical set of integers (`..., -2, -1, 0, 1, 2, ...`) without a fractional or decimal component. PHP integers are strictly signed; the language does not support unsigned integers.

## Internal Representation and Limits

The size of an `int` is platform-dependent, determined by the architecture of the system running PHP.

* On 32-bit systems, the maximum value is typically `2147483647`.
* On 64-bit systems, the maximum value is typically `9223372036854775807`.

PHP provides predefined constants to introspect integer limits at runtime:

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

## Integer Overflow

PHP does not throw an error or wrap around upon integer overflow. If an operation results in a value outside the bounds of the `int` type, PHP automatically promotes the result to a `float`.

Once promoted, the value is subject to standard floating-point formatting rules. Functions like `var_dump()` (which relies on the `precision` INI directive) or `var_export()` (which relies on the `serialize_precision` INI directive) will display the value as a standard float. The output will only use scientific notation if the number's magnitude exceeds the configured precision threshold.

```php theme={"dark"}
$max = PHP_INT_MAX;
var_dump($max);      // int(9223372036854775807) on a 64-bit system

$overflow = $max + 1;
var_dump($overflow); // float(9.223372036854776E+18) - Formatted according to float precision rules
```

## Syntax and Literals

Integers can be specified in decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2) notation. As of PHP 7.4, numeric literal separators (`_`) can be used to improve readability.

```php theme={"dark"}
$decimal = 255;
$hexadecimal = 0xFF;       // Prefix 0x
$binary = 0b11111111;      // Prefix 0b
$octal_legacy = 0377;      // Prefix 0 (Legacy)
$octal_explicit = 0o377;   // Prefix 0o (PHP 8.1+)

$separated = 1_000_000;    // Evaluates to 1000000
```

## Type Casting and Coercion

Values of other types can be explicitly converted to an integer using the `(int)` or `(integer)` casts, or via the `intval()` function.

* **From Float:** The fractional part is dropped (truncated towards zero). Note that casting floats that exceed the bounds of an integer results in undefined behavior prior to PHP 8.0, and well-defined behavior resulting in exactly `0` in PHP 8.0+.
* **From Boolean:** `false` yields `0`, and `true` yields `1`.
* **From Null:** Yields `0`.
* **From String:** If the string starts with numeric data, it resolves to that number. If it does not contain valid numeric data, it resolves to `0`. Explicit casting via `(int)` or `intval()` performs this conversion silently. Warnings or `TypeError`s are only emitted during *implicit* coercion (such as arithmetic operations) with non-well-formed numeric strings in PHP 8.0+.

```php theme={"dark"}
$from_float = (int) 3.99;        // int(3)
$from_float_neg = (int) -3.99;   // int(-3)
$from_bool = (int) true;         // int(1)
$from_null = (int) null;         // int(0)

$from_string = (int) "42";       // int(42)
$from_mixed = (int) "42 apples"; // int(42) - Silently converts
$from_invalid = (int) "apple";   // int(0)  - Silently converts

$out_of_bounds = (int) 1e20;     // int(0)  - PHP 8.0+ behavior
```

## Division Behavior

Unlike languages where integer division yields an integer, the `/` operator in PHP yields a `float` if the result is not an exact integer. To perform strict integer division (discarding the remainder), the `intdiv()` function must be used.

```php theme={"dark"}
$standard_div = 10 / 3;       // float(3.3333333333333)
$integer_div = intdiv(10, 3); // int(3)
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor PHP Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
