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.
如何创建一个函数以使地板的所有数字为 18 的倍数?
例子:
3 => 0 17 => 0 19 => 18 43 => 36 69 => 54
谢谢。
$a = 19; $a -= $a % 18; // => 18
通过使用模运算符 (%)
$a % $b = gives the remainder of $a divided by $b.
在你的情况下,
$a = 3; $a = $a - ($a % 18);