PHP Generate every 2 character combo of the alphabet. Twist: duplicates letters allowed [closed]

五迷三道 提交于 2020-01-17 17:27:10

问题


I believe there is something like 67 million combination of two character strings using only the letters of the alphabet.

I basically want an array in PHP containing something like the following
Array
(
[1] => AA
[2] => AB
[3] => AC
[4] => AD
[5] => AE
[6] => AF
[7] => AG
[8] => AH
[9] => AI
[10] => AJ
.... and so on
)


回答1:


with two loop you can do this:

<?php 
$arr = array('A', 'B', 'C');
foreach ($arr as $value1) {
    foreach ($arr as $value2) {
        echo $value1.$value2;
    }
}
?>

Then you can put the result in an array.



来源:https://stackoverflow.com/questions/17934490/php-generate-every-2-character-combo-of-the-alphabet-twist-duplicates-letters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!