Increment Operator ( ++ )
Incremental Operator (++) is used to increase value of a variable.
<?php
$num=5;
$num++;
echo $num;
?>
Displays the output as 6.
Decrement operator ( -- )
Decremental Operator (--) is used to decrease value of a variable.
<?php
$num=5;
$num--;
echo $num;
?>
Displays the output as 4.
Preincrement operator and Predecrement operator
Example
<?php
$num="5";
echo ++$num;
echo "<BR>";
echo $num;
?>
Displays the output as 6. One more 6 will be displayed in the next line due to BR command.
Similarly, for Pre decrement operator echo --$num; can be used.
Back to Home
|