在PHP中以编程方式循环将char附加到字符串

时间:2012-08-24 04:25:31

标签: php string loops char append

我在这里很困惑。

我该如何循环:

从0-9a-zA-Z

开始

来自上述范围的foreach字母数字字符,我必须创建一个字符串

第一个字符串将是

0000
... ( thousands of string generated between)
0009
... ( thousands of string generated between)
000a
... ( thousands of string generated between)
000z
000A
... ( thousands of string generated between)
000Z
.... ( thousands of string generated between)
ZZZA
... ( thousands of string generated between)
ZZZZ

1 个答案:

答案 0 :(得分:1)

这是一个解决方案:

$corpus = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
for( $i = 0; $i < strlen($corpus); $i++ )
   for( $j = 0; $j < strlen($corpus); $j++ )
      for( $k = 0; $k < strlen($corpus); $k++ )
         for( $l = 0; $l < strlen($corpus); $l++ )
              print substr($corpus, $i, 1).substr($corpus, $j, 1).substr($corpus, $k, 1).substr($corpus, $l, 1)."\n";