Too many arrays! My head is exploding!
| From: | Gary | Date: | Tue, 29 May 2012 12:45:38 +0000 |
| Subject: | Too many arrays! My head is exploding! | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-318014@lists.php.net to get a copy of this message | ||
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!). Normally I'm pretty good at working
this stuff out, but to be honest I'm struggling with this one, at least
to do it in any kind of elegant way. Does anyone have any ideas?
Idealy what I'd like is a multidimensional array depending on the number
of "things" in the combination. Something like:
array(2) {
[0]=>
array(3) {
[0]=>
array(1) {
["name"]=>
string(7) "A"
}
[1]=>
array(2) {
["name"]=>
string(5) "B"
}
[2]=>
array(2) {
["name"]=>
string(4) "C"
}
}
[1]=>
array(...) {
[0]=>
array(2) {
["name"]=>
string(13) "A+B"
}
[1]=>
array(2) {
["name"]=>
string(12) "A+C"
}
(etc.)
--
Gary Please do NOT send me 'courtesy' replies off-list.