我想用PHP列出所有的有26个字母组成的三字符,请问PHP该怎么写了?

解决方案 »

  1.   

    $arr = explode(' ','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');
    for ($i = 0; $i < 26; $i ++) {
       for($j = 0; $j < 26; $j ++) {
          for($k = 0; $k < 26; $k ++) echo $arr[$i].$arr[$j].$arr[$k]."<br />\n";
       }
    }
      

  2.   

    //想起来在PHP中可以直接使用[]来操作字符串,这样就不用把字符串转为数组了:
    $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    for ($i = 0; $i < 26; $i ++) {
       for($j = 0; $j < 26; $j ++) {
          for($k = 0; $k < 26; $k ++) echo $str[$i].$str[$j].$str[$k]."<br />\n";
       }
    }
      

  3.   

    不用那么麻烦:$x="AAA";
    echo $x; 
    while($x!="ZZZ")echo ++$x."\n"; 即可
      

  4.   

    再简化一下吧for($x="AAA";$x!="AAAA";$x++)echo $x."\n";
      

  5.   

    这是我以前写的一个通用的获取最大组合的函数<?php$str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';function getConstitutes($str, $size) {
    $max = strlen($str); for($i=$size; $i > -1; $i--) {
    $b[$i] = pow($max, $i);
    } $ret = array();
    $count = 0;
    while($count < $b[$size]) { $constitute = '';
    for($i= $size-1; $i > -1; $i--) {
    $constitute .= $count / $b[$i] % $max;
    }
    $ret[] = $constitute; $count++;
    } return $ret;
    }
    print_r(getConstitutes($str, 3));
      

  6.   

    想不出比这个简单的了!
    for($x="AAA";$x!="AAAA";$x++)echo $x."\n";