Increment and Decrement Operators
×
Home Courses Community Support
Increment and Decrement Operators

PHP support increment and decrement operators which can be used for pre and post increment and decrement.
 

Pre Increment

This operator in increase the value by 1 and then return the value.

See below example-

<?php
$X = 7;
echo ++$X; //Return the value post increase by 1.
?>

Output:

8


Post Increment

This operator return the value and then increase that by one.

See below example-

<?php
$X = 7;
echo $X++;
var_dump($X);
?>

Output:

7

int 8

In above code the echo print the same value as $X holds because the value was returned before it increamented by one. To check the current valur of $X we have used var_dump() function and found that the value has been increamented by one.
 

Pre Decreament

This operator will decrease the value by one and then return the value.

See below example-

<?php
$X = 7;
echo --$X;
?>

Output:

6

 

Post Decreament

This operator return the value and then decrease the value by one.

<?php
$X = 7;
echo $X--;
var_dump($X);
?>

 Output:

7

int 6

← Preview

Arithmetic Operators

Next →

Assignment Operators

NOTES

Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.

Courses

  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App