I have an array:
$array = array ( 'tag1' => array ('apple', 'orange','cherries') ,
'tag2' => array ('delicious' , 'yummy', 'tasty', 'good')
'tag3' => array ('green', 'red', 'orange')
);
I would like to produce another array with every possible combination regardless of order but including every combination (power set). For example:
$result = array (
array(),
array('tag1' => 'apple'),
array('tag1' => 'orange'),
array('tag1' => 'cherries'),
array('tag2' => 'delicious'),
array('tag2' => 'yummy'),
array('tag2' => 'tasty'),
array('tag2' => 'good'),
array('tag3' => 'green'),
array('tag3' => 'red'),
array('tag3' => 'orange'),
array('tag1' => 'apple', 'tag2' => 'delicious'),
array('tag1' => 'apple', 'tag2' => 'yummy'),
array('tag1' => 'apple', 'tag2' => 'tasty'),
array('tag1' => 'apple', 'tag2' => 'good'),
array('tag1' => 'apple', 'tag3' => 'green'),
array('tag1' => 'apple', 'tag3' => 'red'),
array('tag1' => 'apple', 'tag3' => 'orange'),
array('tag1' => 'apple', 'tag2' => 'delicious', 'tag3' => 'green'),
array('tag1' => 'apple', 'tag2' => 'delicious', 'tag3' => 'red'),
array('tag1' => 'apple', 'tag2' => 'delicious', 'tag3' => 'orange'),
..
);
Does anyone know what function can be written to achieve this? I believe it might have to be a recursive function, but I haven't been able to come up with anything that fits all my requirements so far.