Skip to content

Instantly share code, notes, and snippets.

@Bamuel
Created August 20, 2016 06:45
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 Bamuel/73aa55217fbe0d9208795495ecebcbec to your computer and use it in GitHub Desktop.
Save Bamuel/73aa55217fbe0d9208795495ecebcbec to your computer and use it in GitHub Desktop.
combinations at its finest
<?php
function limit ($n, $input) {
if ($n > 0) {
$tmp_set = array();
$res = limit($n-1, $input);
foreach ($res as $ce) {
foreach ($input as $e) {
array_push($tmp_set, $ce . $e);
}
}
return $tmp_set;
}
else {
return array('→ ');
}
}
$input = array('0','1','2','3','4','5','6','7','8','9');
$input2 = limit(4, $input);
echo "The Epic List <br>";
foreach($input2 as $output) {
print $output . "<br>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment