PHP: is multiple of

Soldato
Joined
15 Dec 2004
Posts
3,819
Hi,

Is there a way of doing a sort of 'is mutliple of' command in PHP. For example:

if $number is a multiple of 3, do something, if not, do something else.

Sorry for being a bit vague :o

Thanks

Ben
 
The modulus operator returns the remainder of the division of the first operand by the second. For example, 4 % 3 returns 1, 17 % 3 returns 2, etc. If the the second operand is a multiple of the first, then the remainder will obviously be 0, which is what we're checkign for there. :)
 
Trigger said:
Cool, thanks Will :) What does the '== 0' bit do? Can't find anything on it in the PHP manual- sorry :o

$x % $y finds the remainder of $x divided by $y. By checking if the remainder is equal to 0—which is what the "== 0" does—checks that there's no remainder left over, which is what happens when $x is divisible by $y.

Edit: GOD DAMN YOU WILLIAM
 
Back
Top Bottom