Hi all,
Is there a function for checking whether an integer is divisible by a whole number such as 12 and/or multiples of 12?
Pseudo code:

if the quantity of an item is equal to 12, 24, 36, 48 etc. statement is true therefore echo the divisible number

The quantity is a user inserted value.

Cheers

    function divisable_by_12($number) {
      return ($number % 12) == 0;
    }

      and to make it more flexible:

      function divisible_by_whole_number($number,$divisor=12)
      {
          return ($number % $divisor) == 0 )
      }
      

        I always use % to alternate color rows

        echo "<table>";
        for($i=0;$i<count($table);$i++){
          $color = ($i%2) ? "#ffffff" : "#000000";
          echo "<tr><td bgcolor=$color>text</td></tr>";
        }
        echo "</table>";
        

          I almost always wear shoes when I'm outside, only sometimes I don't 😉

          $i % 2 returns 1 if $i is a odd number (17 / 2 = 8 and a rest of 1) and 0 if $i is even (18 / 2 = 9 and a rest of 0)

            Write a Reply...