PHP Questions Home | Register | Login
Categories
Arrays
Files
Forms
Creating PDFs
PHP Errors
Functions
Images
MySQL
Numbers
Others
Strings
Website
Unanswered

PHP Forums
Forums Index
MySQL Forum
PHP Forum
Flash/Actionscript
Javascript
Web design

More PHP
PHP Functions
Top Questions
Ask a Question
PHP Interview Questions
PHP Jobs
Ecommerce
IT Questions
Business Websites

Sponsors

sponsor ad
My Salary
PHP Developer Salary
Advertise Here

How do I work out the remainder of a division?


Sometimes you will want to work out the remainder of a division sum, for instance when you divide 7 by 5, the remainder is 2.

There are various mathematical reasons you might want to know the remainder, and it's also useful to know for instance in a grid where you want to know the x,y co-ordinates of a particular cell.

To find the remainder of a division, called the modulus, simply use the percentage symbol - % - like this:

<?php
$value 
7;
echo 
$value 5;
?>


This will print '2' to the screen.



Comment on this Question and Answer >>>

ASK A QUESTION

More numbers PHP Questions

How do I round down a number?

How do I force a value to be treated as a number?

How do I generate a random number?

How do I format a number with commas like a monetary value?

How do I round up a number?



Custom Search