+ 1
I don't understand why it gives 30 in php $ foo = 5; echo $ foo * $ foo ++;
Question about operators
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
+ 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."
0
I thought it gave 26
0
Help