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=>$sum]; } $result = []; for($digit=0; $digit<10 && $sum-$digit>0; $digit++) { foreach(getCombinedSum($digits-1, $sum-$digit) as $subsum) { $result[$digit.$subsum] = $digit.$subsum; $result[$subsum.$digit] = $subsum.$digit; } } return $result; } var_dump(getCombinedSum(3, 2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/lbjQR
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                                                 3
          3        SEND_VAL                                                 2
          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 = 52
Branch analysis from position: 52
2 jumps found. (Code = 46) Position 1 = 54, Position 2 = 57
Branch analysis from position: 54
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 33
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 50
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 50
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 50
2 jumps found. (Code = 46) Position 1 = 54, Position 2 = 57
Branch analysis from position: 54
Branch analysis from position: 57
Branch analysis from position: 50
Branch analysis from position: 57
Branch analysis from position: 14
Branch analysis from position: 11
Branch analysis from position: 8
filename:       /in/lbjQR
function name:  getCombinedSum
number of ops:  60
compiled vars:  !0 = $digits, !1 = $sum, !2 = $result, !3 = $digit, !4 = $subsum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        TYPE_CHECK                                   16  ~5      !0
          3        BOOL_NOT                                         ~6      ~5
          4      > JMPNZ_EX                                         ~6      ~6, ->8
          5    >   TYPE_CHECK                                   16  ~7      !1
          6        BOOL_NOT                                         ~8      ~7
          7        BOOL                                             ~6      ~8
          8    > > JMPNZ_EX                                         ~6      ~6, ->11
          9    >   IS_SMALLER                                       ~9      !0, 1
         10        BOOL                                             ~6      ~9
         11    > > JMPNZ_EX                                         ~6      ~6, ->14
         12    >   IS_SMALLER                                       ~10     !1, 0
         13        BOOL                                             ~6      ~10
         14    > > JMPZ                                                     ~6, ->19
    7    15    >   NEW                                              $11     'InvalidArgumentException'
         16        SEND_VAL_EX                                              'Invalid+numeric+format'
         17        DO_FCALL                                      0          
         18      > THROW                                         0          $11
    9    19    >   MUL                                              ~13     !0, 9
         20        IS_SMALLER                                               ~13, !1
         21      > JMPZ                                                     ~14, ->26
   11    22    >   NEW                                              $15     'LogicException'
         23        SEND_VAL_EX                                              'Sum+out+of+range'
         24        DO_FCALL                                      0          
         25      > THROW                                         0          $15
   13    26    >   IS_EQUAL                                                 !0, 1
         27      > JMPZ                                                     ~17, ->30
   15    28    >   INIT_ARRAY                                       ~18     !1, !1
         29      > RETURN                                                   ~18
   17    30    >   ASSIGN                                                   !2, <array>
   18    31        ASSIGN                                                   !3, 0
         32      > JMP                                                      ->52
   20    33    >   INIT_FCALL_BY_NAME                                       'getCombinedSum'
         34        SUB                                              ~21     !0, 1
         35        SEND_VAL_EX                                              ~21
         36        SUB                                              ~22     !1, !3
         37        SEND_VAL_EX                                              ~22
         38        DO_FCALL                                      0  $23     
         39      > FE_RESET_R                                       $24     $23, ->50
         40    > > FE_FETCH_R                                               $24, !4, ->50
   22    41    >   CONCAT                                           ~25     !3, !4
         42        CONCAT                                           ~27     !3, !4
         43        ASSIGN_DIM                                               !2, ~25
         44        OP_DATA                                                  ~27
   23    45        CONCAT                                           ~28     !4, !3
         46        CONCAT                                           ~30     !4, !3
         47        ASSIGN_DIM                                               !2, ~28
         48        OP_DATA                                                  ~30
   20    49      > JMP                                                      ->40
         50    >   FE_FREE                                                  $24
   18    51        PRE_INC                                                  !3
         52    >   IS_SMALLER                                       ~32     !3, 10
         53      > JMPZ_EX                                          ~32     ~32, ->57
         54    >   SUB                                              ~33     !1, !3
         55        IS_SMALLER                                       ~34     0, ~33
         56        BOOL                                             ~32     ~34
         57    > > JMPNZ                                                    ~32, ->33
   26    58    > > RETURN                                                   !2
   27    59*     > RETURN                                                   null

End of function getcombinedsum

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.17 ms | 1403 KiB | 16 Q