3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getCombinedSum($digits, $sum) { if(!is_int($digits) || !is_int($sum) || $digits<1 || $sum<0) { throw new InvalidArgumentException('Invalid numeric format'); } if($sum>9*$digits) { throw new LogicException('Sum out of range'); } if($digits==1) { return [$sum]; } $result = []; for($digit=0; $digit<10 && $sum-$digit>0; $digit++) { $subsum = join('',getCombinedSum($digits-1, $sum-$digit)); for($j=0; $j<$digits; $j++) { $result[] = substr($subsum, 0, $j).$digit.substr($subsum, $j); } } return $result; } var_dump(getCombinedSum(2, 1));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/1QI5X
function name:  (null)
number of ops:  8
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'getcombinedsum'
          2        SEND_VAL                                                 2
          3        SEND_VAL                                                 1
          4        DO_FCALL                                      0  $0      
          5        SEND_VAR                                                 $0
          6        DO_ICALL                                                 
          7      > RETURN                                                   1

Function getcombinedsum:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 47) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 47) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 26
Branch analysis from position: 22
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
2 jumps found. (Code = 46) Position 1 = 65, Position 2 = 68
Branch analysis from position: 65
2 jumps found. (Code = 44) Position 1 = 69, Position 2 = 33
Branch analysis from position: 69
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 46
Branch analysis from position: 62
2 jumps found. (Code = 46) Position 1 = 65, Position 2 = 68
Branch analysis from position: 65
Branch analysis from position: 68
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 46
Branch analysis from position: 62
Branch analysis from position: 46
Branch analysis from position: 68
Branch analysis from position: 14
Branch analysis from position: 11
Branch analysis from position: 8
filename:       /in/1QI5X
function name:  getCombinedSum
number of ops:  71
compiled vars:  !0 = $digits, !1 = $sum, !2 = $result, !3 = $digit, !4 = $subsum, !5 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        TYPE_CHECK                                   16  ~6      !0
          3        BOOL_NOT                                         ~7      ~6
          4      > JMPNZ_EX                                         ~7      ~7, ->8
          5    >   TYPE_CHECK                                   16  ~8      !1
          6        BOOL_NOT                                         ~9      ~8
          7        BOOL                                             ~7      ~9
          8    > > JMPNZ_EX                                         ~7      ~7, ->11
          9    >   IS_SMALLER                                       ~10     !0, 1
         10        BOOL                                             ~7      ~10
         11    > > JMPNZ_EX                                         ~7      ~7, ->14
         12    >   IS_SMALLER                                       ~11     !1, 0
         13        BOOL                                             ~7      ~11
         14    > > JMPZ                                                     ~7, ->19
    7    15    >   NEW                                              $12     'InvalidArgumentException'
         16        SEND_VAL_EX                                              'Invalid+numeric+format'
         17        DO_FCALL                                      0          
         18      > THROW                                         0          $12
    9    19    >   MUL                                              ~14     !0, 9
         20        IS_SMALLER                                               ~14, !1
         21      > JMPZ                                                     ~15, ->26
   11    22    >   NEW                                              $16     'LogicException'
         23        SEND_VAL_EX                                              'Sum+out+of+range'
         24        DO_FCALL                                      0          
         25      > THROW                                         0          $16
   13    26    >   IS_EQUAL                                                 !0, 1
         27      > JMPZ                                                     ~18, ->30
   15    28    >   INIT_ARRAY                                       ~19     !1
         29      > RETURN                                                   ~19
   17    30    >   ASSIGN                                                   !2, <array>
   18    31        ASSIGN                                                   !3, 0
         32      > JMP                                                      ->63
   20    33    >   INIT_FCALL                                               'join'
         34        SEND_VAL                                                 ''
         35        INIT_FCALL_BY_NAME                                       'getCombinedSum'
         36        SUB                                              ~22     !0, 1
         37        SEND_VAL_EX                                              ~22
         38        SUB                                              ~23     !1, !3
         39        SEND_VAL_EX                                              ~23
         40        DO_FCALL                                      0  $24     
         41        SEND_VAR                                                 $24
         42        DO_ICALL                                         $25     
         43        ASSIGN                                                   !4, $25
   21    44        ASSIGN                                                   !5, 0
         45      > JMP                                                      ->60
   23    46    >   INIT_FCALL                                               'substr'
         47        SEND_VAR                                                 !4
         48        SEND_VAL                                                 0
         49        SEND_VAR                                                 !5
         50        DO_ICALL                                         $29     
         51        CONCAT                                           ~30     $29, !3
         52        INIT_FCALL                                               'substr'
         53        SEND_VAR                                                 !4
         54        SEND_VAR                                                 !5
         55        DO_ICALL                                         $31     
         56        CONCAT                                           ~32     ~30, $31
         57        ASSIGN_DIM                                               !2
         58        OP_DATA                                                  ~32
   21    59        PRE_INC                                                  !5
         60    >   IS_SMALLER                                               !5, !0
         61      > JMPNZ                                                    ~34, ->46
   18    62    >   PRE_INC                                                  !3
         63    >   IS_SMALLER                                       ~36     !3, 10
         64      > JMPZ_EX                                          ~36     ~36, ->68
         65    >   SUB                                              ~37     !1, !3
         66        IS_SMALLER                                       ~38     0, ~37
         67        BOOL                                             ~36     ~38
         68    > > JMPNZ                                                    ~36, ->33
   26    69    > > RETURN                                                   !2
   27    70*     > RETURN                                                   null

End of function getcombinedsum

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.86 ms | 1406 KiB | 20 Q