The reason is that PHP handles variables in a certain way. This is a bit like Visual Basic.
The expression 'a' + 1
uses a mathematical complement. In this context, a
interpreted as a number, so it will be considered 0 (if you are familiar with C, it kind of feeds the string "a" to atoi()
).
If you use the expression 'a' . 1
'a' . 1
, the result will be a1
because of it using string concatenation.
To get the expected result ( b
), you will need to use chr(ord('a') + 1)
, where ord()
explicitly returns the ASCII value of the (first) character.
$a++
is a special case, essentially an overload, considering the ascii value instead of the value itself as a variable.
source share