Breaking News

PHP-MySQLi Series 5.4|| increment or decremenst operators



Increment/Decrement Operators:
This operator is used to increase or decrease the value by 1. Mainly there are two ways to increase or decrease the value of variable. They are : 1) Pre-Increment and Pre-Decrement 
                                                                                   (2) Post-Increment and Post-Decrements.
Examples
Name
Effects
++$x
Pre-increments
Increment $x by one, then return $x
$x++
Post-increments
Return $x, then increment $x by one
--$x
Pre-decrements
Decrement $x by one, then return $x
$x++
Post-decrements
Return $x, then decrement $x by one

Let’s see one by one:


Pre-Increment:
Pre-increment helps to increase by value by 1 and return the value after adding.
example
<?php
$x= 10;
echo ++$x;
?>
Output:
11


Post-Increment:
Post-increment returns the original value $y then only increase the value of $y by one
<?php
$y = 10;
echo $y++;
echo “<br>$y”;
?>

Output:
10
11

Pre-decrements:
 Pre-decrements helps to decrease by value by 1 and return the value after subtracting.
example
<?php
$x= 10;
echo --$x;
?>
Output:
9

Post-Increment:
Post-decrement returns the original value $y then only decrease the value of $y by one
<?php
$y = 10;
echo $y--;
echo “<br>$y”;
?>

Output:
10

9

1 comment: