$a = 'a';
print ($a+1);
print ($a++);
print $a;
The output is: 1 a b
So it is clear that increment operator did its job but I don’t understand why output is ‘1’ in case $a+1. Can anyone explain?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
PHP is not C, so
'a' + 1is not'b'.'a'in a numeric context is0, and0+1 = 1.The fact that the postfix/prefix increment operators do work like if it was a C char seems to be a nasty “feature” of PHP. Especially since the decrement operators are a no-op in this case.
When you increment
'z'it gets even worse: