js 里比较运算符比赋值运算符优先级高。于是 foo = 1
php 里反过来,赋值运算符比比较运算符优先级高。于是 foo = 1
foo = (1
附:php与javascript完整的运算符优先级
js
the following table is ordered from highest (19) to lowest (0) precedence.
precedenceoperator typeassociativityindividual operators
19 grouping n/a ( … )
18 member access left-to-right … . …
computed member access left-to-right … [ … ]
new (with argument list) n/a new … ( … )
17 function call left-to-right … ( … )
new (without argument list) right-to-left new …
16 postfix increment n/a … ++
postfix decrement n/a … --
15 logical not right-to-left ! …
bitwise not right-to-left ~ …
unary plus right-to-left + …
unary negation right-to-left - …
prefix increment right-to-left ++ …
prefix decrement right-to-left -- …
typeof right-to-left typeof …
void right-to-left void …
delete right-to-left delete …
14 exponentiation right-to-left … ** …
multiplication left-to-right … * …
division left-to-right … / …
remainder left-to-right … % …
13 addition left-to-right … + …
subtraction left-to-right … - …
12 bitwise left shift left-to-right …
bitwise right shift left-to-right … >> …
bitwise unsigned right shift left-to-right … >>> …
11 less than left-to-right …
less than or equal left-to-right …
greater than left-to-right … > …
greater than or equal left-to-right … >= …
in left-to-right … in …
instanceof left-to-right … instanceof …
10 equality left-to-right … == …
inequality left-to-right … != …
strict equality left-to-right … === …
strict inequality left-to-right … !== …
9 bitwise and left-to-right … & …
8 bitwise xor left-to-right … ^ …
7 bitwise or left-to-right … | …
6 logical and left-to-right … && …
5 logical or left-to-right … || …
4 conditional right-to-left … ? … : …
3 assignment right-to-left … = …
… += …
… -= …
… **= …
… *= …
… /= …
… %= …
…
… >>= …
… >>>= …
… &= …
… ^= …
… |= …
2 yield right-to-left yield …
1 spread n/a ... …
0
php
operator precedenceassociativityoperatorsadditional information
non-associative clone new clone andnew
left [ array()
right ** arithmetic
right ++ -- ~ (int) (float) (string) (array) (object) (bool) @ types andincrement/decrement
non-associative instanceof types
right ! logical
left * / % arithmetic
left + - . arithmetic andstring
left > bitwise
non-associative >= comparison
non-associative == != === !== comparison
left & bitwise andreferences
left ^ bitwise
left | bitwise
left && logical
left || logical
right comparison
left ? : ternary
right = += -= *= **= /= .= %= &= |= ^= >= => assignment
left and logical
left xor logical
left or logical
以上就介绍了php 与 javascript 的运算符优先级差异,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
