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.
Use the % operator. You can use the modulus operator, if the result is 0 then the function should return true.
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.
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.
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.
if ($count % 20 != 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With