Skip to content

Instantly share code, notes, and snippets.

@dahnielson
Created August 4, 2010 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dahnielson/508886 to your computer and use it in GitHub Desktop.
Save dahnielson/508886 to your computer and use it in GitHub Desktop.
Get letter combinations
<?php
function filterSign($var)
{
return strlen($var) < 2 ? false : true;
}
function getCombinations($values)
{
$perms = array(null);
foreach ($values as $key => $v)
{
$temp = $values;
for ($i=0; $i<=$key; $i++)
unset($temp[$i]);
$newPerms = getCombinations($temp);
foreach ($newPerms as $perm)
$perms[] = ($v . $perm);
}
return $perms;
}
function getLetterCombinations($word)
{
$word_array = str_split($word);
sort($word_array);
return array_filter(getCombinations($word_array), "filterSign");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment