note 20741 added to language.operators
| From: | ronm1958 at adelphia dot net | Date: | Mon, 15 Apr 2002 01:59:46 +0000 |
| Subject: | note 20741 added to language.operators | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-29346@lists.php.net to get a copy of this message | ||
The PHP modulus function will (interestingly) not return the decimal portion of the result. I wrote
a little function that will do so, and mimics the results obtained by using the Windows calculator
mod function:
function modphp($x, $y, $z) {
for ($y = 0; $y <= abs($z); $y++) {
$w = abs($z) - (abs($x) * $y);
if ($w < abs($x)) {
break;
}
}
if ($z < 0) {
return(-$w);
} else {
return($w);
}
}
Here's how to pull the answer out of the mod function above:
$answer = modphp($var_x, $var_y, $var_z);
--
http://www.php.net/manual/en/language.operators.php
http://master.php.net/manage/user-notes.php?action=edit+20741
http://master.php.net/manage/user-notes.php?action=delete+20741
http://master.php.net/manage/user-notes.php?action=reject+20741