php 递增字母导致无限循环

php increment letters results in infinite loop

我无法确定这是 PHP "feature" 还是错误。

像这样循环:

// PHP code
for($i='A1';$i<='c1';$i++){
//something here..
}

导致无限循环。 为什么会这样? c1 应该比 A1 "less" 或者至少当 A1 到达 C1 时它们应该相等。

不过。发生的事情是 $i 一直到 Z1..Z9 然后转到 AA0...等等

你有 'c1' 而不是 'C1',所以它永远不会 >=

听起来您可能想这样做:

// PHP code
for($i='A1';$i<=strtoupper('c1');$i++){
//something here..
}

你在c1中有一个小c,打字错误?

这个有效:

for($i='A1';$i<='C1';$i++){
    //something here..
    Echo $i ."\n";
}

https://3v4l.org/SHK3E