Skip to content

Increment / Decrement Operators in PHP ?

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.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments