note 57535 added to language.operators
| From: | juraj at crimson-imperium dot org | Date: | Thu, 06 Oct 2005 18:33:25 +0000 |
| Subject: | note 57535 added to language.operators | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-96523@lists.php.net to get a copy of this message | ||
Since PHP lacks Pascal-like div and mod operators(integer division and remaining of an integer
division), here are 2 functions (for PHP newbies who are familiar with pascal) which produce the
same effect.
<?
function div($first, $second) {
$result = $first / $second;
return (int) $result;
}
function mod($first, $second) {
$result = $first / $second;
$result = (int) $result;
$result = ($first - ($second * $result));
return $result;
}
// examples
echo div(10, 4); // outputs 2
echo mod(10, 6); // outputs 4
echo div(5, 2) + mod(5, 2); // outputs 3 (2 + 1)
?>
----
Manual Page -- http://www.php.net/manual/en/language.operators.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+57535
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57535&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57535&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57535&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57535&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57535&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57535&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57535&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+57535&report=yes
Search -- http://master.php.net/manage/user-notes.php