note 96597 deleted from language.operators.arithmetic by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:07:36 +0000 |
| Subject: | note 96597 deleted from language.operators.arithmetic by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189821@lists.php.net to get a copy of this message | ||
Note Submitter: dragos dot rusu at NOSPAM dot bytex dot ro
----
Although some would know this, I had to try in order to understand. Modulus and multiplication
operators are not associative; they will execute from left to right.
<?php
$a = 23;
$b = 5;
$c = 2;
$d = $a % $b * $c; // <=> (23%5) * 2 = 3 * 2 = 6
$d2 = $c * $a % $b; // <=> (2*23) % 5 = 46 % 5 = 1
var_dump($d);
var_dump($d2);
?>