Home Tutorial Php Phpbasics Tutorial PHP Increment Decrement Operator

 
 

PHP Increment Decrement Operator
Posted on: March 19, 2010 at 12:00 AM
Advertisement
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

Advertisement

Related Tags for PHP Increment Decrement Operator:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 19, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com