Skip to content

Instantly share code, notes, and snippets.

@jamalnasir
Created August 5, 2018 07:50
Show Gist options
  • Save jamalnasir/093389fc4a262eb1d6649d6586c1cc8f to your computer and use it in GitHub Desktop.
Save jamalnasir/093389fc4a262eb1d6649d6586c1cc8f to your computer and use it in GitHub Desktop.
Letters Combinations
function everyCombination($array) {
try {
// initialize by adding the empty set
$results = [[]];
foreach ($array as $element) {
$this->line($element);
foreach ($results as $combination) {
$this->info(implode('', $combination));
$results[] = array_merge(array($element), $combination);
}
}
$response = [];
foreach($results as $result)
if(count($result) > 1) $response[] = implode('', array_reverse($result));
return $response;
} catch(\Exception $e) {
dd($e->getMessage());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment