Increment & Decrement Operators in PHP

phpIncrement and decrement operators in PHP increment and decrement value by 1.  There are 4 types of increment and decrement operators.

  • Pre-Increment++$variable
  • Post-Increment$variable++
  • Pre-Decrement–$variable
  • Post-Decrement$variable–

Example for increment and decrement operators is given below.

<?php

$pre_increment =  10;
$post_increment =  10;
$pre_decrement =  10;
$post_decrement =  10;

//Pre-Increment: 11
echo 'Pre-Increment:  '.++$pre_increment. '<br />';
 
//Post-Increment: 10
echo 'Post-Increment:  '.$post_increment++. '<br />';

//After Post-Increment: 11
echo 'After Post-Increment:  '.$post_increment. '<br />';

//Pre-decrement: 9
echo 'Pre-decrement:  '.--$pre_decrement. '<br />';

//Post-decrement: 10
echo 'Post-decrement:  '.$post_decrement--. '<br />';

//After Post-decrement: 9
echo 'After Post-decrement:  '.$post_decrement;

?>

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •