PHP-通过字母循环 [英] PHP - loop through letters

查看:167
本文介绍了PHP-通过字母循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图遍历字母而不是数字.

I am trying to loop through letters rather than numbers.

我正在尝试使用chr和等价的数字执行此操作,但似乎没有发生!

I am trying to do this using chr and the number equivalent but it doesn't seem to be happening!

我想要四个字母的循环.

I want four letter loop.

所以AAAA,AAAB,AAAC等到ZZZZ-是的,我知道这可能需要一段时间才能执行!

So AAAA, AAAB, AAAC etc through to ZZZZ - and yes I know this will likely take a while to execute!

推荐答案

为什么不创建字母数组然后使用嵌套循环:

Why don't you make an array of letters and then use nested loops:

$letters = range('A', 'Z');

foreach ($letters as $one) {
  foreach ($letters as $two) {
    foreach ($letters as $three) {
      foreach ($letters as $four) {
        echo "$one$two$three$four";
      }
    }
  }
}

这篇关于PHP-通过字母循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆