PHP MYSQL - Operators - 5.4 Increment / Dercement Operators

 

PHP Increment / Decrement Operators

The PHP increment operators are used to increment a variable's value by adding one.

The PHP decrement operators are used to decrement a variable's value by subtracting one.


OperatorNameDescription
++$xPre-incrementIncrements $x by one, then returns $x
$x++Post-incrementReturns $x, then increments $x by one
--$xPre-decrementDecrements $x by one, then returns $x
$x--Post-decrementReturns $x, then decrements $x by one                        
Example: 
Prefix Increment Operator 
<!DOCTYPE html>
<html>
<body>

<?php
$x = 10;  
echo ++$x;
?>  

</body>
</html>

Output:
11

Example: 
Postfix Increment Operator 
<!DOCTYPE html>
<html>
<body>

<?php
$x = 10;  
echo $x++;
?>  

</body>
</html>
Output:
10

Similarly prefix --, postfix -- operators works


Popular posts from this blog

Install Windows 7 Operating System - Practical

COPA Bits for Computer Based Test (CBT) by Venugopal Vanjarapu

COPA