我如何在PHP中循环A到AAZ。 我可以通过A到Z循环并使用下面的代码
列出它们foreach (range('A', 'Z') as $char) {
echo $char . "\n";
}
有没有办法让我可以通过A循环到AAZ。 所以输出应该是
A,B,C,..Z,AA,AB,AC,AD...AZ,BA,BB,BC...AAZ.
答案 0 :(得分:0)
您必须为此创建多个循环:
// Write A...Z
foreach (range('A', 'Z') as $char) {
echo $char . "\n";
}
// Write AA...ZZ
foreach (range('A', 'Z') as $char1) {
foreach (range('A', 'Z') as $char2) {
echo $char1 . $char2 . "\n";
}
}
// Write AAA...ZZZ
foreach (range('A', 'Z') as $char1) {
foreach (range('A', 'Z') as $char2) {
foreach (range('A', 'Z') as $char3) {
echo $char1 . $char2 . $char3 . "\n";
}
}
}