Home > Article > Backend Development > js intercepts string increment operation code for string under PHP
A classmate asked a question:
Copy the code The code is as follows:
for($i = 'A'; $i <= 'Z'; $i++) {
echo $i;
}
//What is the output?
Copy the code The code is as follows:
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAPAQARAS…….
Copy the code The code is as follows:
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 'AA', 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.
Copy the code The code is as follows:
$name = "laruence";
++$name; //will be "laruencf"
Copy the code The code is as follows:
$name = "laruence";
--$name; //No effect, still "laruence"
The above introduces the incremental operation code for strings under PHP with js intercepting strings, including the content of js intercepting strings. I hope it will be helpful to friends who are interested in PHP tutorials.