Related to Generating all the combinations of a set of boolean variables in Haskell and various other questions of the type.
I have a bunch of toggle switches in a database and want to get a list of all possible settings. The number of switches can change, specifically, users can add or remove.
I can get them into an array like
$switches = array('aaa', 'bbb', 'ccc');
and I would like to generate all possibilities, i.e. something like:
$states = array(
array('aaa' => false, 'bbb' => false, 'ccc' => false),
array('aaa' => false, 'bbb' => false, 'ccc' => true),
array('aaa' => false, 'bbb' => true, 'ccc' => false),
array('aaa' => false, 'bbb' => true, 'ccc' => true),
...
);
I don't particularily care in which order the result set is.
What's an elegant way to generate that?