Skip to content

Instantly share code, notes, and snippets.

@Mulkave
Created August 16, 2015 11:39
Show Gist options
  • Save Mulkave/942991fea8f9ed5f556f to your computer and use it in GitHub Desktop.
Save Mulkave/942991fea8f9ed5f556f to your computer and use it in GitHub Desktop.
Get all the possible combinations between the items of the given array
<?php
function allCombinationsForPossibilities(array $possibilities)
{
// initialize by adding the empty set
$results = array(array( ));
foreach ($possibilities as $element) {
foreach ($results as $combination) {
$results[] = array_merge(array($element), $combination);
}
}
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment