note 96597 modified in language.operators.arithmetic by danbrown

From: Date: Sun, 07 Mar 2010 14:56:45 +0000
Subject: note 96597 modified in language.operators.arithmetic by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-166757@lists.php.net to get a copy of this message
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); ?> --was-- 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); ?> http://php.net/manual/en/language.operators.arithmetic.php

« previous php.notes (#166757) next »