<?php
function combs($letters) {
$result = array_fill(0, count($letters)+1, array());
var_dump($result);
$lettersCount = count($letters);
for ($i = 0; $i < $lettersCount; ++$i) {
for ($j = $lettersCount - $i; $j > 0; --$j) {
$result[$j][] = implode(', ', array_slice($letters, $i, $j));
}
}
array_shift($result);
return $result;
}
$arr = array('a', 'b', 'c', 'd', 'e', 'f');
print_r(combs($arr));
- Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.38, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- array(7) {
[0]=>
array(0) {
}
[1]=>
array(0) {
}
[2]=>
array(0) {
}
[3]=>
array(0) {
}
[4]=>
array(0) {
}
[5]=>
array(0) {
}
[6]=>
array(0) {
}
}
Array
(
[0] => Array
(
[0] => a
[1] => b
[2] => c
[3] => d
[4] => e
[5] => f
)
[1] => Array
(
[0] => a, b
[1] => b, c
[2] => c, d
[3] => d, e
[4] => e, f
)
[2] => Array
(
[0] => a, b, c
[1] => b, c, d
[2] => c, d, e
[3] => d, e, f
)
[3] => Array
(
[0] => a, b, c, d
[1] => b, c, d, e
[2] => c, d, e, f
)
[4] => Array
(
[0] => a, b, c, d, e
[1] => b, c, d, e, f
)
[5] => Array
(
[0] => a, b, c, d, e, f
)
)
preferences:
295.45 ms | 407 KiB | 452 Q