在 PHP 中查找数字的倍数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2809864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find multiples of a number in PHP
提问by dotty
I want to find all muliples of a number in PHP.
我想在 PHP 中找到一个数字的所有复数。
I'm using something like this
我正在使用这样的东西
if($count != 20 )
to work out if $countis not equal to 20.
计算 if$count不等于 20。
But I also need this script to check if $countis not equal to 20, 40, 60, 80, 100, 120, 140, 160 etc.
但我也需要这个脚本来检查是否$count不等于 20、40、60、80、100、120、140、160 等。
Any ideas? I think i need to use the modulus symbol (%), but I don't know.
有任何想法吗?我想我需要使用模数符号 ( %),但我不知道。
回答by Marcelo Cantos
if ($count % 20 != 0)
回答by richsage
if ($count % 20 != 0)
{
// $count is not a multiple of 20
}
回答by marianboda
If you don't want zero to be excluded:
如果您不想排除零:
if ($count % 20 != 0 || $count == 0)
回答by Klaus Byskov Pedersen
You can do it like so:
你可以这样做:
if($count % 20 != 0)

