note 10445 added to Operators

From: Date: Thu, 04 Jan 2001 00:54:35 +0000
Subject: note 10445 added to Operators
Groups: php.notes 
Request: Send a blank email to php-notes+get-9361@lists.php.net to get a copy of this message
Normal, a negative value modulo a positive number generates a negaive number, if you don't want that (for example, the number has to be between 0 and 9 and not negative) then you can use a function like this: function mod($a,$b) { if ($a <= 0) return (int) mod($b-abs($a), $b); else return (int) $a % $b; } for example: -2 % 10 = -2 but mod(-2, 10) will return 8. http://www.php.net/manual/language.operators.php

« previous php.notes (#9361) next »