PHP - 错误的字母表循环 [英] PHP - Erroneous Alphabet Loop
问题描述
<?php
for($ i ='a'; $ i< ='z'; $ i ++){
echo$ i;
}
?>
为什么它的输出是:
abcdefghijklmnopqrstu vwxyz aa ab ac ad ae af
ag ah a a a al al a a a ap ap a ar as as au av aw ax ay az ba bb bc
bd be bf bg bh bi bj bk bl bm bn bo bp bq br bs bt bu bv bw bx by bz
ca cb cc cd ce cf cg ch ci cj ck c c c c c c c c c c c c c c cr cr cs ct cu cv cw
cx cy cz da db dc dd de df dg dh di dj dk dl dm dn do dp dq dr ds dt
du dv dw dx dy dy ez ee ee ee e e e e e e e e e e e e e e e e e
er es et eu ev ew ex ex ... on to yz
但是它的工作方式很好
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ b回显$ i;
}
?>
循环似乎反复运行直到达到zz。 b
$ b
如果我给 $ i
请参阅在字符上的运算符
$ b
'Z'; $ A ++;将$ a变成'AA',而C a ='Z';一个++;将a变成
'['('Z'的ASCII值是90,'['的ASCII值是91')。请注意,
字符变量可以递增,但不能递减,即使只支持
纯ASCII字符(a-z和A-Z)。
增加/减少其他字符变量不起作用,
原始字符串不变。
Can Anyone Explain me why :
<?php
for ($i = 'a'; $i <= 'z'; $i++){
echo "$i ";
}
?>
Why its Output is :
a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az ba bb bc bd be bf bg bh bi bj bk bl bm bn bo bp bq br bs bt bu bv bw bx by bz ca cb cc cd ce cf cg ch ci cj ck cl cm cn co cp cq cr cs ct cu cv cw cx cy cz da db dc dd de df dg dh di dj dk dl dm dn do dp dq dr ds dt du dv dw dx dy dz ea eb ec ed ee ef eg eh ei ej ek el em en eo ep eq er es et eu ev ew ex... on to yz
But its Working Fine With
<?php
for ($i = 'a'; $i != 'aa'; $i++){
echo "$i ";
}
?>
The loop seems to run over and over again until it reaches "zz".
If I give $i<"aa"
it should work fine but instead it outputs only "a".
See the manual for the increment operator:
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 characters (a-z and A-Z) are supported. Incrementing/decrementing other character variables has no effect, the original string is unchanged.
这篇关于PHP - 错误的字母表循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!