
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 |
Advertisements