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

The `%` operator in PHP is the arithmetic modulo (or integer remainder) operator. It evaluates the remainder of the integer division between a dividend (left operand) and a divisor (right operand).

```php theme={"dark"}
$remainder = $dividend % $divisor;
```

## Operand Evaluation and Type Coercion

Before the modulo operation is executed, PHP implicitly casts both operands to integers. This casting process strips the fractional part of floating-point numbers (truncation towards zero) rather than rounding them.

As of PHP 8.1.0, implicitly casting a float with a fractional part to an integer emits a deprecation warning. To perform an integer modulo on floating-point numbers without triggering this warning, operands must be explicitly cast to integers.

```php theme={"dark"}
// PHP 8.1+: Emits "Deprecated: Implicit conversion from float to int loses precision"
// 5.9 truncates to 5, 2.3 truncates to 2
$implicit = 5.9 % 2.3; // Evaluates as 5 % 2, returning 1

// Explicit casting prevents the deprecation warning
$explicit = (int)5.9 % (int)2.3; // Returns 1
```

## Sign Determination

The sign of the resulting remainder is strictly determined by the dividend. The sign of the divisor is ignored during the evaluation.

```php theme={"dark"}
$a =  5 %  3; // Returns  2
$b =  5 % -3; // Returns  2 (Divisor sign is ignored)
$c = -5 %  3; // Returns -2 (Takes dividend sign)
$d = -5 % -3; // Returns -2 (Takes dividend sign)
```

## Division by Zero

If the divisor evaluates to `0` (either explicitly or after float-to-integer truncation), PHP throws a `DivisionByZeroError` exception.

```php theme={"dark"}
$result = 10 % 0; // Throws DivisionByZeroError

// PHP 8.1+: Emits deprecation warning for 0.8, then throws DivisionByZeroError 
// because 0.8 truncates to 0
$result = 10 % 0.8; 
```

## Floating-Point Modulo Alternative

Because the `%` operator forces integer casting, it cannot be used to calculate the remainder of floating-point division. For exact floating-point modulo operations without truncation or deprecation warnings, PHP provides the built-in `fmod()` function.

```php theme={"dark"}
// % operator (Emits deprecation warning in PHP 8.1+, truncates to 5 % 1)
$intMod = 5.7 % 1.3; // Returns 0

// fmod() function (Preserves floating-point precision, no warnings)
$floatMod = fmod(5.7, 1.3); // Returns 0.5
```

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