递增循环中的字符,递减不?

因此,我进行了一些练习并遍历了以下代码(产生“ 1. Item A”,“ 2.Item B”等):

echo "\n<ol>";
for ($x='A'; $x<'G'; $x++){
    echo "<li>Item $x</li>\n";
}
echo "\n</ol>";

很好奇,我尝试做相反的操作(这会产生Z的无限循环):

echo "\n<ol>";
for ($x = 'Z'; $x > 'M'; $x--){
    echo "<li>Item $x</li>\n";
}
echo "\n</ol>";

我在这里错过了什么?

解决方法:

PHP follows Perl’s convention when dealing with arithmetic operations
on character variables and not C’s. For example, in PHP and Perl $a =
‘Z’; $a++; turns $a into ‘AA’, while in C a = ‘Z’; a++; turns a into
‘[‘ (ASCII value of ‘Z’ is 90, ASCII value of ‘[‘ is 91). Note that
character variables can be incremented but not decremented and even so
only plain ASCII alphabets and digits (a-z, A-Z and 0-9) are
supported. Incrementing/decrementing other character variables has no
effect, the original string is unchanged.

从PHP手册link

上一篇:捕获tweepy中的所有关注者


下一篇:header("location:test.php")跳转成功需要注意的