In this tutorial, you shall learn about Arithmetic Modulus Operator in PHP, its syntax, and how to use this operator in PHP programs, with examples.

PHP Modulus

PHP Arithmetic Modulus Operator takes two numbers as operands and returns the remainder of the integer division (first operand / second operand).

Symbol

% symbol is used for Modulus Operator.

Syntax

The syntax for modulus operator is

</>
Copy
operand_1 % operand_2

The operands could be of any numeric datatype: integer or float.

Examples

1. Modulus of Integers

In the following example, we take integer values in $x and $y, and find the remainder of the division $x / $y.

PHP Program

</>
Copy
<?php
  $x = 9;
  $y = 4;

  $output = $x % $y;

  echo "x = $x" . "<br>";
  echo "y = $y" . "<br>";
  echo "x % y = $output";
?>

Output