I have tried this code
$a = array_fill(0, 4, NULL); $a[0]++; ++$a[1]; $a[2]--; --$a[3]; var_dump($a);
Result:
array(4) { [0]=> int(1) [1]=> int(1) [2]=> NULL [3]=> NULL }
Why value of 2 and 3 index is not negative?
The ++ (increment) and -- (decrement) operators have been known to contribute to bad code by encouraging excessive trickiness. They are second only to faulty architecture in enabling to viruses and other security menaces.
JavaScript Arithmetic (Math) Decrementing (--)The decrement operator ( -- ) decrements numbers by one. If used as a postfix to n , the operator returns the current n and then assigns the decremented the value. If used as a prefix to n , the operator assigns the decremented n and then returns the changed value.
2) Decrement Operators: The decrement operator is used to decrement the value of a variable in an expression. In the Pre-Decrement, the value is first decremented and then used inside the expression. Whereas in the Post-Decrement, the value is first used inside the expression and then decremented.
The increment operator ( ++ ) increments its operand by 1 ; that is, it adds 1 to the existing value. There's a corresponding decrement operator ( -- ) that decrements a variable's value by 1 . That is, it subtracts 1 from the value.
Weird, but documented on the Incrementing/Decrementing Operators php doc page:
Note: The increment/decrement operators do not affect boolean values. Decrementing NULL values has no effect too, but incrementing them results in 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With