3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function computeCombination(array $source,$picks,$startIndex=0,array $pad=array()) { if($picks<=0) { return $pad; } elseif($picks>=count($source)-$startIndex) { return array_merge($pad,array_slice($source,$startIndex)); } $result=array(); foreach(range($startIndex,count($source)-$picks) as $subStartIndex) { $subPad=$pad; $subPad[]=$source[$subStartIndex]; $result=array_merge($result,array(computeCombination($source,$picks-1,$subStartIndex+1,$subPad))); } return $result; } print_r(computeCombination(array(1,2,3,4,5,6,7,8),6));
Output for 5.1.0 - 7.1.0
Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 ) [1] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 7 ) [2] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 8 ) ) [1] => Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 6 [5] => 7 ) [1] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 6 [5] => 8 ) ) [2] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 7 [5] => 8 ) ) [1] => Array ( [0] => Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 5 [4] => 6 [5] => 7 ) [1] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 5 [4] => 6 [5] => 8 ) ) [1] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 5 [4] => 7 [5] => 8 ) ) [2] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 6 [4] => 7 [5] => 8 ) ) [1] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 [4] => 6 [5] => 7 ) [1] => Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 [4] => 6 [5] => 8 ) ) [1] => Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 5 [4] => 7 [5] => 8 ) ) [1] => Array ( [0] => 1 [1] => 2 [2] => 4 [3] => 6 [4] => 7 [5] => 8 ) ) [2] => Array ( [0] => 1 [1] => 2 [2] => 5 [3] => 6 [4] => 7 [5] => 8 ) ) [1] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => 1 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 7 ) [1] => Array ( [0] => 1 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 8 ) ) [1] => Array ( [0] => 1 [1] => 3 [2] => 4 [3] => 5 [4] => 7 [5] => 8 ) ) [1] => Array ( [0] => 1 [1] => 3 [2] => 4 [3] => 6 [4] => 7 [5] => 8 ) ) [1] => Array ( [0] => 1 [1] => 3 [2] => 5 [3] => 6 [4] => 7 [5] => 8 ) ) [2] => Array ( [0] => 1 [1] => 4 [2] => 5 [3] => 6 [4] => 7 [5] => 8 ) ) [1] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 7 ) [1] => Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 6 [5] => 8 ) ) [1] => Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 5 [4] => 7 [5] => 8 ) ) [1] => Array ( [0] => 2 [1] => 3 [2] => 4 [3] => 6 [4] => 7 [5] => 8 ) ) [1] => Array ( [0] => 2 [1] => 3 [2] => 5 [3] => 6 [4] => 7 [5] => 8 ) ) [1] => Array ( [0] => 2 [1] => 4 [2] => 5 [3] => 6 [4] => 7 [5] => 8 ) ) [2] => Array ( [0] => 3 [1] => 4 [2] => 5 [3] => 6 [4] => 7 [5] => 8 ) )
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/Im6rN on line 2
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/Im6rN on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_ARRAY, expecting ')' in /in/Im6rN on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/Im6rN on line 2
Process exited with code 255.