in reply to mod function

;-), obviously you did the right thing... See, it is the same as in other languages. A tiny suggestion, you also can say things like:
if (!($y % 3)) { }