Skip to content

Instantly share code, notes, and snippets.

@JanPetterMG
Last active January 25, 2016 18:00
Show Gist options
  • Save JanPetterMG/7234c65c0eba019412d8 to your computer and use it in GitHub Desktop.
Save JanPetterMG/7234c65c0eba019412d8 to your computer and use it in GitHub Desktop.
PHP: Generate all possible alphabetical combinations of given strings
/**
* 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