Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
power set of and array
function pc_array_power_set($array, $limit){
$subset = array();
$results = array(array());
foreach ($array as $element){
foreach ($results as $combination){
$result = array_merge(array($element), $combination);
array_push($results, $result);
if(count($result) == $limit){
$subset[] = $result;
return $subset;
$set = range(1, 15);
print_r(pc_array_power_set($set, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment