PHP Operator Precedence

Description

An operator with a higher precedence is executed before an operator with lower precedence. For example,

3 + 4 * 5

In the case of the example, * has a higher precedence than + , so PHP multiplies 4 by 5 first, then adds 3 to the result to get 23.

Precedence of Some PHP Operators (Highest First)

A list of the operators in order of precedence (highest first):


++  --  (increment/decrement)    /*from w  w  w. j  a va2 s .  co  m*/
(int) (float) (string) (array) (object) (bool) (casting)    
! (not)    
* / % (arithmetic)    
+  -  . (arithmetic)    
<     < =  >     > =  <  >  (comparison)    
== != === !== (comparison)    
&&  (and)    
|| (or)    
= +=  - = *= /= .= %= (assignment)    
and     
xor    
or    

Parentheses

You can affect the order of execution of operators in an expression by using parentheses. So, for example, the following expression evaluates to 35:

( 3 + 4 ) * 5




















Home »
  PHP Tutorial »
    Language Basic »




PHP Introduction
PHP Operators
PHP Statements
Variable
PHP Function Create
Exception
PHP Class Definition