Home Tutorial Php Phpbasics Tutorial PHP Increment Decrement Operator

 
 

PHP Increment Decrement Operator
Posted on: March 19, 2010 at 12:00 AM
In this tutorial we will study about increment and decrement operators, PHP follows 'C' style increment and decrement operators. Examples in this tutorial will make it more clear.

PHP Incrementing and Decrementing variables:

PHP follows very common style of increment and decrement, much like C,C++. but in few cases it follows Perl style, e.g. if we perform  'Z'+1 then PHP will display 'AA' whereas in 'C' and 'Java' result would be '['.

Examples:

<?php

$a=12;

echo "Pre increment value of a is:".++$a."<br/>";

echo "Post increment value of a is:".$a++."<br/>";

echo "After post increment value of a is:".$a."<br/>";

echo "Pre decrement value of a is:".--$a."<br/>";

echo "Post decrement value of a is:".$a--."<br/>";

echo "After post decrement value of a is:".$a--."<br/>";

?>

Output:

Pre increment value of a is:13
Post increment value of a is:13
After post increment value of a is:14
Pre decrement value of a is:13
Post decrement value of a is:13
After post decrement value of a is:12

Related Tags for PHP Increment Decrement Operator:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.