Last active
January 25, 2016 18:00
-
-
Save JanPetterMG/7234c65c0eba019412d8 to your computer and use it in GitHub Desktop.
PHP: Generate all possible alphabetical combinations of given strings
This file contains 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
/** | |
* Generate all possible alphabetical combinations of given strings | |
* | |
* @param array $strings - Strings to combine | |
* @param array $combinationArray - for internal use only | |
* @param int $start - for internal use only | |
* @param string $prefix - for internal use only | |
* @return array | |
*/ | |
function generateCombinations($strings, &$combinationArray = array(), $start = 0, $prefix = "") | |
{ | |
for ($i = $start; $i < count($strings); $i++) { | |
$combination = $prefix . $strings[$i]; | |
$combinationArray[] = $combination; | |
$this->generateCombinations($strings, $combinationArray, ++$start, $combination); | |
} | |
return $combinationArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment