note 57535 deleted from language.operators by nlopess

From: Date: Tue, 11 Oct 2005 08:06:01 +0000
Subject: note 57535 deleted from language.operators by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-96816@lists.php.net to get a copy of this message
Note Submitter: juraj at crimson-imperium dot org ---- 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) ?>

« previous php.notes (#96816) next »