php floor a number as times of 18
Question
How to make a function so that make floor all the number as times of 18?
example:
3 => 0
17 => 0
19 => 18
43 => 36
69 => 54
Thanks.
Solution
$a = 19;
$a -= $a % 18; // => 18
OTHER TIPS
By using Modulus operator (%)
$a % $b = gives the remainder of $a divided by $b.
In your case,
$a = 3;
$a = $a - ($a % 18);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow