如何递归迭代字母表?

2022-01-24 00:00:00 algorithm iteration php

我需要编写一个像这样遍历字母 (a-z) 的函数:
(这里是 a-c 的例子)

I need to write a function which iterates through alphabet (a-z) like this:
(here is an example for a-c)

a
b
c

aa
ab
ac

ba
bb
bc

ca
cb
cc

aaa
aab
aac

... and so on. (until the word has 5 characters)

知道怎么做吗?我想我需要一些递归函数.

any idea how to do this? I guess I need some recursive function.

推荐答案

无需递归!

for($char = 'a'; $char != 'aaaaaa'; $char++){
    echo $char . PHP_EOL;
}

相关文章