Last updated 195 days ago by Monty Shokeen

phpPHP has a total of eight arithmetic operators. The most common are addition (`+`

), subtraction (`-`

), multiplication (`*`

), and division (`/`

). A slightly lesser-known, though still very important operator is modulo (`%`

). In this tutorial, we'll focus on the modulo operator. We will discuss what it does and some of its practical uses.

If you have two variables `$a`

and `$b`

, calculating `$a % $b`

—usually pronounced "a modulo b" or "a mod b"—will give you the remainder after dividing `$a`

by `$b`

. Modulo is an integer operator, so it converts both the operands to integers before calculating the remainder. So basically modulo does integer division and then gives back whatever is left from the dividend.

The sign of the value returned by a modulo operation is determined by the sign of the dividend. In division, the result after dividing two negative numbers will be a positive number. However, that's not the case with the modulo operator. The sign of the divisor has no effect on the final value.

- react
- javascript
- django
- python
- kotlin
- nodejs
- golang
- css
- php
- flutter
- angular
- swift
- ruby
- dotnet
- ios
- android
- html
- raspberrypi
- redux
- webpack
- vuejs
- ES6
- npm
- sql
- yarn
- java
- docker
- c
- arduino
- apache
- git
- c
- coffeescript
- linux
- sass
- Lua
- sql
- typescript
- rails
- laravel
- handlebars
- webassembly
- bitbucket
- csharp
- yeoman
- jquery
- d3
- mongodb
- jasmine
- ionic
- npm
- bootstrap
- bulma
- less
- backbone
- foundation
- fuse
- bower
- mocha
- jade