
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP Operator Precedence
Introduction
Precedence of operators decides the order of execution of operators in an expression. For example in 2+6/3, division of 6/3 is done first and then addition of 2+2 takesplace because division operator / has higher precedence over addition operator +. To force a certain operator to be called before other, parentheses should be used. In this example, (2+6)/3 performs addition first, followed by division.
Some operators may have same level of precedence. In that case, the order of associativity (either left or right) decides the order of operations. Operators of same precedence level but are non-associativem cannot be used next to each other. Following table lists PHP operators with decreasing order of precedence
Operators | purpose |
clone new | clone and new |
** | exponentiation |
++ -- | increment/decrement |
~(int) (float) (string) (array) (object) (bool) | casting |
instanceof | types |
! | logical |
* / | multiplication/division |
% | modulo |
+ - . | arithmetic and string |
<< >> | bitwise shift |
< <= > >= | comparison |
== != === !== <> <=> | comparison |
& | bitwise and/references |
^ | bitwise XOR |
| | bitwise OR |
&& | logical and |
|| | logical or |
?? | null coalescing |
? : | ternary |
= += -= *= **= /= .= %= &= |= ^= <<= >>= ??= | assignment operators |
yield from | yield from |
yield | yield |
and | logical |
xor | logical |
or | logical |
- Related Articles
- According to Java Operator precedence, which operator has the highest precedence?
- What is Operator Precedence Parsing?
- Operator Precedence and Associativity in C
- Can we change operator precedence in Python?
- What is the operator precedence in C#?
- What is C Operator Precedence and Associativity?
- What are Precedence Relations in Operator Grammar?
- How Can MySQL operator precedence affect result set?
- Explain Operator grammar and precedence parser in TOC
- Evaluating a mathematical expression considering Operator Precedence in JavaScript
- What is Operator Precedence Parsing Algorithm in compiler design?
- How does the precedence of || operator depend on PIPES_AS_CONCAT SQL mode?
- What are LEADING and TRAILING operation of an operator precedence grammar?
- PHP Execution Operator
- In MySQL, how does the precedence of ! operator in comparison with NOT operator depends upon HIGH_NOT_PRECEDENCE SQL mode?

Advertisements