When processing the arithmetic operation of character variables, PHP follows the Perl habit, not C. Some people asked a question:
The code is as follows:
For ($ I = 'a'; $ I <= 'Z'; $ I ++ ){
Echo $ I;
}
What is output?
The output is:
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARAS .......
Why?
In fact, it is very simple. it is also explained in the PHP manual, but I am afraid many people will not read the manual carefully in one chapter:
PHP follows Perl's convention when dealing with arithmetic operations on character variables and not C's. for example, in Perl 'Z' + 1 turns into 'A', while in C 'Z' + 1 turns into '[' (ord ('Z') = 90, ord ('[') = 91 ). note that character variables can be incremented but not decremented and even so only plain ASCII characters (a-z and A-Z) are supported.
When processing the arithmetic operation of character variables, PHP follows the Perl habit, not C. For example, in Perl, 'Z' + 1 will get 'A', and in C, 'Z' + 1 will get '[' (ord ('Z ') = 90, ord ('[') = 91 ). Note that character variables can only increase, cannot decrease, and only letters (a-z and A-Z) are supported ).
That is to say, if:
The code is as follows:
$ Name = "laruence ";
+ + $ Name; // it will be "laruencf"
And:
The code is as follows:
$ Name = "laruence ";
-- $ Name; // no effect, or "laruence"
Therefore, the cause of this problem is that when $ I = Z, ++ $ I becomes AA, and if the string is compared,
AA, BB, XX until YZ are all less than or equal to Z... So ..