|
Current Topic: View Topic Tree |
Everything > Science & Technology > Computers > Programming > PHP |
|---|
|
|
pre-increment |
|
|
convert to uppercase |
|
|
post-increment |
|
|
round up |
|
|
convert to double precision |
In the PHP programming language, the symbol ++ immediately before a variable causes a pre-increment operation on that variable. In other words, 1 is added to the value of the variable before the variable is evaluated by the current statement.
For example, consider the following code:
$x = 5;
$y = ++$x + 3;
After this code executes, $x will hold the value 6, because it was incremented. And, more importantly, $y will hold the value 9, because the increment to $x happened before the addition of 3 and the assignment of the result to $y. Compare this with the post-increment operation in the following code:
$x = 5;
$y = $x++ + 3;
After the above code executes, $x will hold the value 6, because it was incremented. And, more importantly, $y will hold the value 8, because the increment to $x happened after the addition of 3 and the assignment of the result to $y.
In addition to the decrement operator ++, there is also an increment operator: --. It operates in the same manner, but it decrements (subtracts 1) from a variable instead of incrementing it (adding 1). It too can be applied either immediately before the variable to pre-decrement, or immediately after the variable to post-decrement.