Re: Too many arrays! My head is exploding!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Florian Lemaitre wrote:

> Le 29/05/2012 14:45, Gary a écrit :
>> Okay, let's assume I have three "things", A, B, and C. I need to
> produce
>> an array with a list of all possible combinations of them, however
> many
>> there might be in those combinations: e.g. A, B, C, D, AB, AC, AD, BC,
>> ABC (not sure if I've missed any!).

> Enjoy !
>
> function combinations($letters) {
>     $combinations = array(array());
>     foreach ($letters as $letter) {
>       foreach ($combinations as $combination) {
>         $combinations[] = array_merge($combination, array($letter));
>       }
>     }
>     return $combinations;
> }

:-) Looks to do pretty much exactly what I want, thanks! The key is the
array_merge, I guess :) Let's just say I wrote a *lot* more code than
that :")

-- 
Gary        Please do NOT send me 'courtesy' replies off-list.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux