views:

215

answers:

5

Hay i need help.

I want to find all muliples of a number in PHP.

I'm using something like this

if($count != 20 )

to work out if $count is not equal to 20.

but i also need this script to check if $count is not equal to 20,40,60,80,100,120,140,160 etc.

Any ideas? I think i need to use the modulus symbol (%), but i don't know.

Thanks

+9  A: 
if ($count % 20 != 0)
Marcelo Cantos
+3  A: 

You can do it like so:

if($count % 20 != 0)
klausbyskov
+5  A: 
if ($count % 20 != 0)
{
  // $count is not a multiple of 20
}
richsage
+2  A: 

if you don't want zero to be excluded:

if (($count % 20 != 0) || ($count == 0))

praksant
A: 

if ($count % 3 == 0 || $count == 0){

That helped me quite a lot. To get the multiples of 3.

nattu