+ 1

I don't understand why it gives 30 in php $ foo = 5; echo $ foo * $ foo ++;

Question about operators

17th Sep 2020, 2:18 PM
Germani benitez alfonso
Germani benitez alfonso - avatar
4 Answers
+ 6
++ has a higher precedence than * https://www.php.net/manual/en/language.operators.precedence.php Therefore, $foo * $foo ++; = $foo * ($foo++); = 5 * 6 = 30
17th Sep 2020, 2:29 PM
Ore
Ore - avatar
+ 5
Also, quoted from the manual page given by Ore above ... "Operator precedence and associativity only determine how expressions are grouped, they do not specify an order of evaluation. PHP does not (in the general case) specify in which order an expression is evaluated and code that *assumes* a specific order of evaluation should be avoided, because the behavior can change between versions of PHP or depending on the surrounding code."
17th Sep 2020, 2:34 PM
Ipang
0
I thought it gave 26
17th Sep 2020, 2:20 PM
Germani benitez alfonso
Germani benitez alfonso - avatar
0
Help
17th Sep 2020, 2:24 PM
Germani benitez alfonso
Germani benitez alfonso - avatar