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

`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

```<?php
\$x = 9;
\$y = 4;

\$output = \$x % \$y;

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

Output

2. Modulus of Float Values

In the following example, we take floating point values in `\$x` and `\$y`, and find the result of division `\$x / \$y`.

PHP Program

```<?php
\$x = 9.5;
\$y = 4.1;

\$output = \$x % \$y;

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

Output

Conclusion

In this PHP Tutorial, we learned how to use Arithmetic Modulus Operator to find the remainder in the division operation.