Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find multiples of a number in PHP

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.

like image 270
dotty Avatar asked May 11 '10 10:05

dotty


People also ask

How do you check if a number is a multiple of another PHP?

Use the % operator. You can use the modulus operator, if the result is 0 then the function should return true.

How do you find the number of multiples of a number?

How to Find Multiples of Numbers. To find multiples of a number, multiply the number by any whole number. For example, 5 × 3 = 15 and so, 15 is the third multiple of 5. For example, the first 5 multiples of 4 are 4, 8, 12, 16 and 20.

How do you check if a number is a multiple of 10?

When you multiply a number by 10 you will get the number attached with zero as the result. eg: 10 × 2 = 20. Multiples of 10 are even numbers that end with 0. If a number is ending with 0 then it is always divisible by 10.

How do you find multiples of 6?

The rule for recognising multiples of 6 is that the number must end in 0, 2, 4, 6, or 8 and the digits must add up to make a number in the 3 times table. For example, 318 is a multiple of 6 because it ends in an 8 and the digits 3 + 1 + 8 add to make 12, which is a number in the 3 times table.


1 Answers

if ($count % 20 != 0) 
like image 101
Marcelo Cantos Avatar answered Sep 30 '22 08:09

Marcelo Cantos