Posted by Arjun on Thursday 28th November 2013

Increment / Decrement Operators in PHP ?

Decrement Increment Operators PHP Code Snippets

Increment and Decrement Operators are common in many Languages,

Increment Operator is represented by ++
Decrement Operator is represented by --

Pre-increment or Pre-decrement:

if you Put increment or Decrement Operator before the variable, operation is done to the variable first then the result is returned.

Post-increment or Post-decrement:

if you put increment or decrement operator after the variable, Operation is done after the variable returned.

Short Description:
++$a(Pre-increment) = Increments $a by one, then returns $a.
$a++(Post-increment) = Returns $a, then increments $a by one.
--$a(Pre-decrement) = Decrements $a by one, then returns $a.
$a--(Post-decrement) = Returns $a, then decrements $a by one.