Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在 php 中检查 $var1 == 90+180*n
其中n是所有自然数,即。1,2,3,4...
提前致谢。
只需使用:
$var1 % 180 == 90
根据模运算的定义,这正是您所需要的
您需要包含括号以确保您的计算正确。
if ( $var1 == (90+(180*n) ) )
或者在检查之前计算您的价值:
$checkme = 90 + (80*$n); if ( $var1 == $checkme ) {}