Pre- and Post- Increment Operator ( ++ ) - PHP

Description

Pre-increment ( ++$y; ) : Increments $y by one , then returns $y .
Post-increment ( $y++; ) : Returns $y , then increments $y by one .
( Unary operator )

Pre- Increment Operator - Example :


<?php

$b ; $a = 0 ; // Declare Variables
$b = ++$a ;
print (" b = {$b} ");
print (" a = {$a} ");

?>

    

Output :


b = 1 a = 1
    

Post- Increment Operator - Example :


<?php

$y ; $z = 0 ; // Declare Variables
$y = $z++ ;
print (" y = {$y} ");
print (" z = {$z} ");

?>

Output :


        y = 0 z = 1

----The PHP version used in this example is 8.4.5 ----

Previous : Null Coalescing Operator ( ?? ) - PHP …

Next : Network data on the hosting server - PHP …

^