Example name effect + + $ a add the value of $ a plus one, and then return $. $ A ++ returns $ a after adding, and then adds the value of $. -- Minus $ a before $ a minus one, and then returns $. $ A -- returns $ a after subtraction, and then drops the value of $ a by one. PHP supports the C-style ascending and descending operators.
Note: the increment/decrement operator does not affect Boolean values. Decreasing the NULL value does not work, but the result of increasing the NULL value is 1.
Increment/decrease operator
Example
Name
Effect
+ + $ A add the value of $ a plus one, and then return $.
$ A ++ returns $ a after adding, and then adds the value of $.
-- Minus $ a before $ a minus one, and then returns $.
$ A -- returns $ a after subtraction, and then drops the value of $ a by one.
A simple example script:
\n";echo "Should be 6: " . $a . "
\n";echo "Preincrement";$a = 5;echo "Should be 6: " . ++$a . "
\n";echo "Should be 6: " . $a . "
\n";echo "Postdecrement";$a = 5;echo "Should be 5: " . $a-- . "
\n";echo "Should be 4: " . $a . "
\n";echo "Predecrement";$a = 5;echo "Should be 4: " . --$a . "
\n";echo "Should be 4: " . $a . "
\n";?>
When processing the arithmetic operation of character variables, PHP follows the Perl habit, not C. For example, in Perl, $ a = 'Z'; $ a ++ changes $ a to 'A', while in C, a = 'Z '; a ++; converts a to '[' (The ASCII value of 'Z' is 90, and the ASCII value of '[' is 91 ). Note that character variables can only increase, cannot decrease, and only letters (a-z and A-Z) are supported ). Otherwise, the variable is invalid and the original string does not change.
Example #1 arithmetic operation involving character variables
The above routine will output:
XYZAAABAC