Re: List all possible 2 letter combinations of 8 letters
| From: | Jason Murray | Date: | Mon, 20 Nov 2000 20:06:48 +0000 |
| Subject: | Re: List all possible 2 letter combinations of 8 letters | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-26309@lists.php.net to get a copy of this message | ||
Ben Weinberger wrote:
>
> Hi~
> I'm trying to write a script that will list all 2 letter combinations of
> given number of letters. For example, let's say I entered 8 letters "a, b,
> c, d, e, f, g, h". I want the script to spit out all 2 letter
> combinations-- i.e. ab, ac, ad, ae, etc.... Also, the script should make
> sure it doesn't repeat any combinations-- I really have no idea where to
> start on this one-- the only thing I know is that it will most likely be
> within some sort of for/while loop... can someone help?
>
> Thanks,
> -Ben
>
Off the top of my head...
$foo = { "a", "b", "c", "d", "e", "f",
"g", "h" };
$dim = 8;
for ($n0 = 0; n0 < dim; n0++) {
for (n1 = 0; n1 < dim; n1++) {
echo $foo[n0] . $foo[n1]);
}
}
Greetings,
Jason
--
Jason Murray
Developer
jWeb New Media Design
1 877 525 jWEB