Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $result = array();
- $combination = array();
- function combinations(array $myArray, $choose) {
- global $result, $combination;
- $n = count($myArray);
- function inner ($start, $choose_, $arr, $n) {
- global $result, $combination;
- if ($choose_ == 0) array_push($result,$combination);
- else for ($i = $start; $i <= $n - $choose_; ++$i) {
- array_push($combination, $arr[$i]);
- inner($i + 1, $choose_ - 1, $arr, $n);
- array_pop($combination);
- }
- }
- inner(0, $choose, $myArray, $n);
- return $result;
- }
- $comb = combinations(array(1,2,3,4,5,6,7,8,9,10), 5);
- foreach ( $comb as $c) {
- foreach ( $c as $e ) echo "$e ";
- echo "<br />";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement