checking if a number is divisible by 6 PHP

前端 未结 11 1720
不思量自难忘°
不思量自难忘° 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:35

    Why don't you use the Modulus Operator?

    Try this:

    while ($s % 6 != 0) $s++;
    

    Or is this what you meant?

    ;
     $k= $s % 6;
    
     if($k !=0)    $s=$s+6-$k;
    ?>
    

提交回复
热议问题