> ## 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 Division

The `/` operator in PHP is the arithmetic division operator used to calculate the quotient of two numeric operands, dividing the left operand (dividend) by the right operand (divisor).

```php theme={"dark"}
$quotient = $dividend / $divisor;
```

## Return Type Resolution

Unlike strictly typed C-family languages where dividing two integers always yields an integer, PHP dynamically resolves the return type based on the mathematical result, the types of the operands, and integer overflow boundaries:

1. **`int`**: Returned only if both operands evaluate to integers, the dividend is an exact multiple of the divisor (i.e., there is no fractional remainder), *and* the result does not exceed the maximum integer limit (`PHP_INT_MAX`).
2. **`float`**: Returned if either operand is a float, if the division of two integers results in a fractional value, or in the event of an integer overflow. Specifically, dividing `PHP_INT_MIN` by `-1` yields a `float` because the positive result exceeds `PHP_INT_MAX`.

```php theme={"dark"}
var_dump(10 / 2);            // int(5)
var_dump(10 / 3);            // float(3.3333333333333335)
var_dump(10.0 / 2);          // float(5)
var_dump(PHP_INT_MIN / -1);  // float(...) - Integer overflow fallback
```

*Note: To enforce strict integer division (truncating the fractional part), PHP provides the `intdiv()` function.*

## Type Coercion

PHP's engine automatically performs type juggling on non-numeric scalar operands prior to execution. Valid numeric strings—which may contain characters such as `.`, `e`, `E`, `+`, `-`, and whitespace—are coerced into either `int` or `float` depending on their format.

```php theme={"dark"}
var_dump("10" / "2");    // int(5) - Strings coerced to integers
var_dump("10.5" / 2);    // float(5.25) - String coerced to float
var_dump(" 1e1 " / 2);   // float(5) - Scientific notation string coerced to float
```

If an operand is a *non-numeric string* (a string that cannot be parsed as a valid integer or float), PHP 8.0 and later will throw a `TypeError`.

## Division by Zero Behavior

The behavior of the `/` operator when the divisor evaluates to zero depends on the PHP version:

* **PHP 8.0 and later:** Throws a `DivisionByZeroError` exception for any zero divisor (`0`, `0.0`, or `"0"`).
* **PHP 7.x:** Emits an `E_WARNING` ("Division by zero") and evaluates the expression to `false` for any zero divisor, regardless of whether it is an integer `0` or a float `0.0`.

```php theme={"dark"}
// PHP 8.0+ Error Handling
try {
    $result = 10 / 0;
} catch (DivisionByZeroError $e) {
    // Execution halts and transfers to the catch block
}
```

## Operator Precedence

The `/` operator shares the same precedence level as multiplication (`*`) and modulo (`%`). It has higher precedence than addition (`+`) and subtraction (`-`). Associativity is strictly left-to-right.

```php theme={"dark"}
$result = 10 + 20 / 5; 
// Evaluates as 10 + (20 / 5) -> 14

$result = 20 / 5 / 2;  
// Evaluates as (20 / 5) / 2 -> 2
```

<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>
