checking if a number is divisible by 6 PHP

前端 未结 11 1722
不思量自难忘°
不思量自难忘° 2020-12-13 02:15

I want to check if a number is divisible by 6 and if not I need to increase it until it becomes divisible.

how can I do that ?

11条回答
  •  一个人的身影
    2020-12-13 02:41

    For micro-optimisation freaks:

    if ($num % 6 != 0)
        $num += 6 - $num % 6;
    

    More evaluations of %, but less branching/looping. :-P

提交回复
热议问题