Changing values by one in PHP
It is possible to increment value of a variable by one in PHP by using ++ operation. ++ operation can either precede or follow a variable.
Preceding or to following a variable changes the priority of incrementing or decreasing operations.
If ++ or — sings precede a variable then operation to this variable will happen first, and then operation with already changed variable will happen.
For example, if we have a variable $i which value is 1, then outputting ++$i will result in 2, and the value of this variable will be 2.
If ++ signs are behind the variable, then outputting value will output the current value of a variable and increasing operation will happen next.
Output of such operation will be 1, however the value of this variable will be 2 after this operation.
Comments
Post a Comment