I am trying for 2 days to create a function to get all possible array combinations (without order repetitions):
public function power_set($array) {
// initialize by adding the empty set
$results = array(array( ));
foreach ($array as $element)
foreach ($results as $combination)
array_push($results, array_merge($combination,array($element)));
return $results;
}
$keys = array(0=>1,1=>2,3=>3,21=>4,4=>5,5=>6,6=>7,7=>8,9=>10,10=>23,11=>34234,12=>34234,13=>34234,14=>45435,15=>32343,16=>35324,17=>4535345,18=>5645645,19=>234,20=>23324);
echo '<pre>'.print_r(power_set($keys),true).'</pre>';
It work fine for a 7 element array, but more than than it dont't. How can I fix it?