Rumah > pembangunan bahagian belakang > tutorial php > 请问生成字母加数字

请问生成字母加数字

WBOY
Lepaskan: 2016-06-13 12:24:10
asal
1240 orang telah melayarinya

请教生成字母加数字
有26个字母{a-Z}和10个数字{0-9}
如果要生成8位字符的,区分大小写,
这样的排列是(26+26+10)8次方=218340105584896个,这218万亿
但相邻不能有两个或以上相同的如{a1b2cc90,这个字符出现了两次cc}
这样的数据可以用PHP来产生吗?
如果生成单个文本数据应该不太可能,得切割成好多份……
------解决思路----------------------
这个意思?

$d = str_split('abcd');<br />print_r(array_map('join', f(4, $d)));<br /><br />function f($n, $d) {<br />  $t = array_chunk($d, 1);<br />  if($n > 2) $t = f($n-1, $d);<br />  foreach($t as $x)<br />    foreach(array_chunk($d, 1) as $y) {<br />      if(end($x) != end($y)) $r[] = array_merge($x, $y);<br />    }<br />  return $r;<br />}
Salin selepas log masuk
Array<br />(<br />    [0] => abab<br />    [1] => abac<br />    [2] => abad<br />    [3] => abca<br />    [4] => abcb<br />    [5] => abcd<br />    [6] => abda<br />    [7] => abdb<br />    [8] => abdc<br />    [9] => acab<br />    [10] => acac<br />    [11] => acad<br />    [12] => acba<br />    [13] => acbc<br />    [14] => acbd<br />    [15] => acda<br />    [16] => acdb<br />    [17] => acdc<br />    [18] => adab<br />    [19] => adac<br />    [20] => adad<br />    [21] => adba<br />    [22] => adbc<br />    [23] => adbd<br />    [24] => adca<br />    [25] => adcb<br />    [26] => adcd<br />    [27] => baba<br />    [28] => babc<br />    [29] => babd<br />    [30] => baca<br />    [31] => bacb<br />    [32] => bacd<br />    [33] => bada<br />    [34] => badb<br />    [35] => badc<br />    [36] => bcab<br />    [37] => bcac<br />    [38] => bcad<br />    [39] => bcba<br />    [40] => bcbc<br />    [41] => bcbd<br />    [42] => bcda<br />    [43] => bcdb<br />    [44] => bcdc<br />    [45] => bdab<br />    [46] => bdac<br />    [47] => bdad<br />    [48] => bdba<br />    [49] => bdbc<br />    [50] => bdbd<br />    [51] => bdca<br />    [52] => bdcb<br />    [53] => bdcd<br />    [54] => caba<br />    [55] => cabc<br />    [56] => cabd<br />    [57] => caca<br />    [58] => cacb<br />    [59] => cacd<br />    [60] => cada<br />    [61] => cadb<br />    [62] => cadc<br />    [63] => cbab<br />    [64] => cbac<br />    [65] => cbad<br />    [66] => cbca<br />    [67] => cbcb<br />    [68] => cbcd<br />    [69] => cbda<br />    [70] => cbdb<br />    [71] => cbdc<br />    [72] => cdab<br />    [73] => cdac<br />    [74] => cdad<br />    [75] => cdba<br />    [76] => cdbc<br />    [77] => cdbd<br />    [78] => cdca<br />    [79] => cdcb<br />    [80] => cdcd<br />    [81] => daba<br />    [82] => dabc<br />    [83] => dabd<br />    [84] => daca<br />    [85] => dacb<br />    [86] => dacd<br />    [87] => dada<br />    [88] => dadb<br />    [89] => dadc<br />    [90] => dbab<br />    [91] => dbac<br />    [92] => dbad<br />    [93] => dbca<br />    [94] => dbcb<br />    [95] => dbcd<br />    [96] => dbda<br />    [97] => dbdb<br />    [98] => dbdc<br />    [99] => dcab<br />    [100] => dcac<br />    [101] => dcad<br />    [102] => dcba<br />    [103] => dcbc<br />    [104] => dcbd<br />    [105] => dcda<br />    [106] => dcdb<br />    [107] => dcdc<br />)<br /><br />
Salin selepas log masuk

------解决思路----------------------

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan