You’ve run into a debate as to what mod (%) really is, and whether negative numbers are allowed. Excel defined mod to be: MOD(n, d) = n - d × INT(n/d) and with that int() in there, the question becomes how to round a negative integer. php chose to do it purely on the math of calculating the remainder, which is different.
I just wrote this, so do some testing, but it may work:
function mod($n,$d)
{
return $n - $d * floor($n/$d);
}
The definition gets a bit ambiguous when dealing with negatives. Different languages deal with it differently, so you will get this disparity in different programs/languages.
Thanks, guys. At least I now know why! I think I vaguely remember this as an issue when I first started programming, more years ago than I care to admit.