3v4l.org

run code in 300+ PHP versions simultaneously
<?php function computeCombination(array $source,$picks,$startIndex=0,array $pad=array()) { if($picks<=0) { return $pad; } elseif($picks>=count($source)-$startIndex) { return array(array_merge($pad,array_slice($source,$startIndex))); } $result=array(); foreach(range($startIndex,count($source)-$picks) as $subStartIndex) { $subPad=$pad; $subPad[]=$source[$subStartIndex]; if(empty($pad))// to make the output look nice { $result=array_merge($result,computeCombination($source,$picks-1,$subStartIndex+1,$subPad)); } else { $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,9,10,11,12,13,14,15,16,17,18,19,20),10));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qbWnK
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   INIT_FCALL                                               'print_r'
          1        INIT_FCALL                                               'computecombination'
          2        SEND_VAL                                                 <array>
          3        SEND_VAL                                                 10
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function computecombination:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 22
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 30, Position 2 = 66
Branch analysis from position: 30
2 jumps found. (Code = 78) Position 1 = 31, Position 2 = 66
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 51
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 66
filename:       /in/qbWnK
function name:  computeCombination
number of ops:  69
compiled vars:  !0 = $source, !1 = $picks, !2 = $startIndex, !3 = $pad, !4 = $result, !5 = $subStartIndex, !6 = $subPad
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      0
          3        RECV_INIT                                        !3      <array>
    4     4        IS_SMALLER_OR_EQUAL                                      !1, 0
          5      > JMPZ                                                     ~7, ->8
    6     6    > > RETURN                                                   !3
          7*       JMP                                                      ->22
    8     8    >   COUNT                                            ~8      !0
          9        SUB                                              ~9      ~8, !2
         10        IS_SMALLER_OR_EQUAL                                      ~9, !1
         11      > JMPZ                                                     ~10, ->22
   10    12    >   INIT_FCALL                                               'array_merge'
         13        SEND_VAR                                                 !3
         14        INIT_FCALL                                               'array_slice'
         15        SEND_VAR                                                 !0
         16        SEND_VAR                                                 !2
         17        DO_ICALL                                         $11     
         18        SEND_VAR                                                 $11
         19        DO_ICALL                                         $12     
         20        INIT_ARRAY                                       ~13     $12
         21      > RETURN                                                   ~13
   12    22    >   ASSIGN                                                   !4, <array>
   13    23        INIT_FCALL                                               'range'
         24        SEND_VAR                                                 !2
         25        COUNT                                            ~15     !0
         26        SUB                                              ~16     ~15, !1
         27        SEND_VAL                                                 ~16
         28        DO_ICALL                                         $17     
         29      > FE_RESET_R                                       $18     $17, ->66
         30    > > FE_FETCH_R                                               $18, !5, ->66
   15    31    >   ASSIGN                                                   !6, !3
   16    32        FETCH_DIM_R                                      ~21     !0, !5
         33        ASSIGN_DIM                                               !6
         34        OP_DATA                                                  ~21
   17    35        ISSET_ISEMPTY_CV                                         !3
         36      > JMPZ                                                     ~22, ->51
   19    37    >   INIT_FCALL                                               'array_merge'
         38        SEND_VAR                                                 !4
         39        INIT_FCALL_BY_NAME                                       'computeCombination'
         40        SEND_VAR_EX                                              !0
         41        SUB                                              ~23     !1, 1
         42        SEND_VAL_EX                                              ~23
         43        ADD                                              ~24     !5, 1
         44        SEND_VAL_EX                                              ~24
         45        SEND_VAR_EX                                              !6
         46        DO_FCALL                                      0  $25     
         47        SEND_VAR                                                 $25
         48        DO_ICALL                                         $26     
         49        ASSIGN                                                   !4, $26
         50      > JMP                                                      ->65
   23    51    >   INIT_FCALL                                               'array_merge'
         52        SEND_VAR                                                 !4
         53        INIT_FCALL_BY_NAME                                       'computeCombination'
         54        SEND_VAR_EX                                              !0
         55        SUB                                              ~28     !1, 1
         56        SEND_VAL_EX                                              ~28
         57        ADD                                              ~29     !5, 1
         58        SEND_VAL_EX                                              ~29
         59        SEND_VAR_EX                                              !6
         60        DO_FCALL                                      0  $30     
         61        INIT_ARRAY                                       ~31     $30
         62        SEND_VAL                                                 ~31
         63        DO_ICALL                                         $32     
         64        ASSIGN                                                   !4, $32
   13    65    > > JMP                                                      ->30
         66    >   FE_FREE                                                  $18
   26    67      > RETURN                                                   !4
   27    68*     > RETURN                                                   null

End of function computecombination

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.8 ms | 1403 KiB | 22 Q