This question already has an answer here:
I am new to php
, for some reason the increment/decrement works inversely. Can someone tell me the reason behind this?
<?php
$var1 = 3;
echo "Addition = " . ($var1 += 3) . "<br>" ;
echo "Subtraction = " . ($var1 -= 3) . "<br>" ;
echo "Multiplication = " . ($var1 *= 3) . "<br>" ;
echo "Divison = " . ($var1 /= 3) . "<br>" ;
echo "Increment = " . $var1++ ;
echo "Decrement = " . $var1-- ;
?>
</div>
If you know how the increment and decrement operators work, you'll get the answer.
echo "Increment = " . $var1++ ;
//Prints $var1 and then increments the value
echo "Decrement = " . $var1-- ;
// Prints the incremented value from previous operation and then decrements the value
To achieve what you are trying to do, use --$var1