Created
August 16, 2015 11:39
-
-
Save Mulkave/942991fea8f9ed5f556f to your computer and use it in GitHub Desktop.
Get all the possible combinations between the items of the given array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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