How to tell if number fits evenly?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Pineriver
Forum Commoner
Posts: 50
Joined: Fri Aug 15, 2003 5:24 pm

How to tell if number fits evenly?

Post by Pineriver »

I would like to tell if a number can be divided into 7 evenly, and if true exicute the code.

$number = 7;
or
$number = 14;
or
$number = 21;
and so on...

if($number / 7) ? but always returns true
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

if ($number % 7 == 0)
{
//stuff here
}
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

adding to that...
% is called modulo/modulus.
$a % $b returns the remainder of $a / $b.
e.g. 10 % 4 = 2
Post Reply