问题描述
<?php
for ($i = 'a'; $i <= 'z'; $i++)
echo "$i\n";
此代码段提供以下输出(换行符替换为空格):
This snippet gives the following output (newlines are replaced by spaces):
推荐答案
来自文档:
例如,在Perl中,'Z'+1
变为'AA'
,而在C中,'Z'+1
变为'['
(ord('Z') == 90
,ord('[') == 91
).
For example, in Perl 'Z'+1
turns into 'AA'
, while in C 'Z'+1
turns into '['
( ord('Z') == 90
, ord('[') == 91
).
请注意,字符变量可以递增但不能递减,即使如此,仅支持纯ASCII字符(a-z和A-Z).
Note that character variables can be incremented but not decremented and even so only plain ASCII characters (a-z and A-Z) are supported.
来自评论:-
还应注意,<=
是词典比较,因此'z'+1 ≤ 'z'
. (自'z'+1 = 'aa' ≤ 'z'
起.但是'za' ≤ 'z'
是第一次比较不正确.)例如,在$i == 'z'
可行时中断.
From Comments:-
It should also be noted that <=
is a lexicographical comparison, so 'z'+1 ≤ 'z'
. (Since 'z'+1 = 'aa' ≤ 'z'
. But 'za' ≤ 'z'
is the first time the comparison is false.) Breaking when $i == 'z'
would work, for instance.
这篇关于为什么此代码不简单地将字母A打印到Z?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!