note 105629 added to language.operators.arithmetic
| From: | Stuart at osu1 dot php dot net | Date: | Fri, 02 Sep 2011 03:10:10 +0000 |
| Subject: | note 105629 added to language.operators.arithmetic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182893@lists.php.net to get a copy of this message | ||
Simpler and less dependent on an artifact of the PHP that could conceivably change.
<?php
for ($x=0; $x<14; $x++) {
if ($x % 3 === 0) { // if $x divisable by 3 remainder == 0
echo $x . ' is divisible by 3 <br>';
}
}
?>
Actual output:
0 is divisible by 3
3 is divisible by 3
6 is divisible by 3
9 is divisible by 3
12 is divisible by 3
Obviously this will not work for floats but they require more care as in an arbitrary case one can
never be sure they divide exactly.
----
Server IP: 69.147.83.197
Probable Submitter: 58.170.196.170
----
Manual Page -- http://www.php.net/manual/en/language.operators.arithmetic.php
Edit -- https://master.php.net/note/edit/105629
Del: integrated -- https://master.php.net/note/delete/105629/integrated
Del: useless -- https://master.php.net/note/delete/105629/useless
Del: bad code -- https://master.php.net/note/delete/105629/bad+code
Del: spam -- https://master.php.net/note/delete/105629/spam
Del: non-english -- https://master.php.net/note/delete/105629/non-english
Del: in docs -- https://master.php.net/note/delete/105629/in+docs
Del: other reasons-- https://master.php.net/note/delete/105629
Reject -- https://master.php.net/note/reject/105629
Search -- https://master.php.net/manage/user-notes.php