Home > Backend Development > PHP Tutorial > Understand the precedence and associativity of operators in PHP

Understand the precedence and associativity of operators in PHP

WBOY
Release: 2016-07-25 08:44:07
Original
1613 people have browsed it

Generally speaking, operators have a set of priorities, which is the order in which they are executed.
Operators are also associative, that is, the execution order of operators with the same priority. This order is usually from left to right (referred to as left), right to left (referred to as right), or irrelevant.
The following table gives a brief list of operators and correlations in PHP. The rule for their appearance is that the top operator has the lowest priority. According to the order from top to bottom in the table, the priority increases.
Associativity Operator
left ,
left or
left xor
left and
right print
Left = += -= *= /= .= %= &= |= ^= ~= >=
Left ?:
Left ||
Left &&
Left |
Left ^
Left &
Left == != === !==
Left >=
Left >
Left + - .
Left * / %
Right ! - ++ == (int) (double) (string) (array) (object) @
Right []
Not relevant new
Not relevant ()

The operator with the highest precedence is: ordinary parentheses, because it can avoid the operator precedence rules.

php


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template