Skip to content

Instantly share code, notes, and snippets.

@mrself
mrself / index.php
Created October 21, 2018 22:59
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);