-4

I want to generate a list of all possible two character strings containing alphanumerics only i.e. 36^2 combinations. I want to print this out with a linebreak between each possibility.

I hope someone could help me out with this.

akki
  • 2,021
  • 1
  • 24
  • 35
reinierkors
  • 507
  • 6
  • 19
  • 4
    What did you come up with yourself? – PeeHaa Apr 17 '14 at 20:12
  • 1
    Please show whatever code or pseudocode you've tried. – kojiro Apr 17 '14 at 20:12
  • Im assuming you mean permutations? Because if it was combinations AB would be the same as BA. And so the number of results would be `36C2` not 36^2 – Krimson Apr 17 '14 at 20:23
  • Duplicate of [Generate all possible combinations using a set of strings](http://stackoverflow.com/questions/12160843/generate-all-possible-combinations-using-a-set-of-strings) and many, many more – Mark Baker Apr 17 '14 at 20:24

1 Answers1

1

Just modify the $characters array to include all the characters you want.


Code:
<?php
    $characters = array('a', 'b', 'c', 'd');
    foreach($characters as $first){
        foreach($characters as $second){
        echo $first.$second.'<br/>';
        }   
    }
?>

Output:

aa
ab
ac
ad
ba
bb
bc
bd
ca
cb
cc
cd
da
db
dc
dd
Krimson
  • 7,386
  • 11
  • 60
  • 97