What exactly does this mean?
$number = ( 3 - 2 + 7 ) % 7;
Since so many people say "modulus finds the remainder of the divisor", let's start by defining exactly what a remainder is.
In mathematics, the remainder is the amount "left over" after performing some computation. In arithmetic, the remainder is the integer "left over" after dividing one integer by another to produce an integer quotient (integer division).
See: http://en.wikipedia.org/wiki/Remainder
So % (integer modulus) is a simple way of asking, "How much of the divisor is left over after dividing?"
To use the OP's computation of (3 - 2 + 7) = 8 % 7 = 1:
It can be broken down into:
(3 - 2 + 7) = 8 8 / 7 = 1.143 #Rounded up .143 * 7 = 1.001 #Which results in an integer of 17 can go into 8 1 time with .14 of 7 leftover
That's all there is to it. I hope this helps to simplify how exactly modulus works.
Additional examples using different divisors with 21.
Breakdown of
21 % 3 = 0:21 / 3 = 7.0 3 * 0 = 0(3 can go into 21 7 times with 0 of 3 leftover)
Breakdown of
21 % 6 = 3:21 / 6 = 3.5 .5 * 6 = 3(6 can go into 21 3 times with .5 of 6 leftover)
Breakdown of
21 % 8 = 5:21 / 8 = 2.625 .625 * 8 = 5(8 can go into 21 2 times with .625 of 8 leftover)