本文介绍了如何在PHP中从A到Z列出,然后到AA,AB,AC等列出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何从A到Z列出:

I know how to list from A to Z:

foreach (range('A', 'Z') as $char) {
  echo $char . "\n";
}

但是如何从那里继续列出AA,AB,AC,AD,... AZ,BA,BB,BC等?

But how do I go on from there to list AA, AB, AC, AD, ... AZ, BA, BB, BC and so on?

我做了一个快速的Google搜索,但找不到任何东西,尽管我猜想方法会有所不同.

I did a quick Google search and couldn't find anything, though I guess the approach will be different.

我认为我可以通过使用for循环和内部带有字母的数组来做到这一点,尽管这种方式似乎有点不合理.

I think I can do it by using a for loop and an array with the letters inside, though that way seems a bit uncouth.

还有其他方法吗?

谢谢.

推荐答案

PHP的字符串增量运算符可以做到这一点:

PHP has the string increment operator that does exactly that:

for($x = 'A'; $x < 'ZZ'; $x++)
    echo $x, ' ';

结果:

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... 

参考:

http://php.net/manual/en/language.operators.increment.php

这篇关于如何在PHP中从A到Z列出,然后到AA,AB,AC等列出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 20:12