gpt4 book ai didi

PHP - 错误的字母循环

转载 作者:行者123 更新时间:2023-12-03 23:04:50 25 4
gpt4 key购买 nike

谁能解释一下原因:

    <?php
for ($i = 'a'; $i <= 'z'; $i++){
echo "$i ";
}
?>

为什么它的输出是:

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

但它与

配合得很好
    <?php
for ($i = 'a'; $i != 'aa'; $i++){
echo "$i ";
}
?>

循环似乎一遍又一遍地运行,直到到达“zz”。

如果我给$i<"aa"它应该可以正常工作,但它只输出“a”。

最佳答案

请参阅 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 - 错误的字母循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8360736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com