Skip to content

Instantly share code, notes, and snippets.

@mrself
Created October 21, 2018 22:59
Show Gist options
  • Save mrself/abaf723a79ccc90527f60f4879ddb2e0 to your computer and use it in GitHub Desktop.
Save mrself/abaf723a79ccc90527f60f4879ddb2e0 to your computer and use it in GitHub Desktop.
PHP make combination array
function getCombination($input, $carry, &$result, $maxLength = null)
{
$maxLength = $maxLength ?: count($input);
$oldCarry = $carry;
foreach ($input as $index => $i) {
$carry[] = $i;
if (count($carry) <= $maxLength) {
$result[] = $carry;
}
getCombination(array_slice($input, $index + 1), $carry, $result, $maxLength);
$carry = $oldCarry;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment