3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function powerSet($in,$minLength = 1) { $count = count($in); $members = pow(2,$count); $return = array(); for ($i = 0; $i < $members; $i++) { $b = sprintf("%0".$count."b",$i); echo $b . "\n"; $out = array(); for ($j = 0; $j < $count; $j++) { if ($b{$j} == '1') $out[] = $in[$j]; } if (count($out) >= $minLength) { $return[] = $out; } } return $return; } $x = powerSet(array(1,2)); foreach($x as $r) { echo implode($r, ' ') . "\n"; }
Output for 4.3.0 - 7.1.0
00 01 10 11 2 1 1 2