3v4l.org

run code in 500+ PHP versions simultaneously
<?php $a = Array( Array(1,2,3), Array(4,5,6), Array(7,8,9) ); function find_paths($array) { if (count($array) == 1) return $array[0]; $output = array(); foreach (array_shift($array) as $v1) { foreach (find_paths($array) as $v2) { $output[] = array_merge(array($v1), is_array($v2) ? $v2 : array($v2)); } } return $output; } $combinations = find_paths($a); print_r($combinations); $sums = array_map(function ($v) { return array_sum($v);}, $combinations); print_r($sums);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7UvS6b
function name:  (null)
number of ops:  18
compiled vars:  !0 = $a, !1 = $combinations, !2 = $sums
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   17     1        INIT_FCALL                                                   'find_paths'
          2        SEND_VAR                                                     !0
          3        DO_FCALL                                          0  $4      
          4        ASSIGN                                                       !1, $4
   18     5        INIT_FCALL                                                   'print_r'
          6        SEND_VAR                                                     !1
          7        DO_ICALL                                                     
   19     8        INIT_FCALL                                                   'array_map'
          9        DECLARE_LAMBDA_FUNCTION                              ~7      [0]
         10        SEND_VAL                                                     ~7
         11        SEND_VAR                                                     !1
         12        DO_ICALL                                             $8      
         13        ASSIGN                                                       !2, $8
   20    14        INIT_FCALL                                                   'print_r'
         15        SEND_VAR                                                     !2
         16        DO_ICALL                                                     
         17      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7UvS6b
function name:  {closure:/in/7UvS6b:19}
number of ops:  6
compiled vars:  !0 = $v
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV                                                 !0      
          1        INIT_FCALL                                                   'array_sum'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $1      
          4      > RETURN                                                       $1
          5*     > RETURN                                                       null

End of Dynamic Function 0

Function find_paths:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 33
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 33
Branch analysis from position: 12
2 jumps found. (Code = 77) Position 1 = 16, Position 2 = 31
Branch analysis from position: 16
2 jumps found. (Code = 78) Position 1 = 17, Position 2 = 31
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 31
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/7UvS6b
function name:  find_paths
number of ops:  36
compiled vars:  !0 = $array, !1 = $output, !2 = $v1, !3 = $v2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    6     0  E >   RECV                                                 !0      
    7     1        COUNT                                                ~4      !0
          2        IS_EQUAL                                                     ~4, 1
          3      > JMPZ                                                         ~5, ->6
          4    >   FETCH_DIM_R                                          ~6      !0, 0
          5      > RETURN                                                       ~6
    8     6    >   ASSIGN                                                       !1, <array>
    9     7        INIT_FCALL                                                   'array_shift'
          8        SEND_REF                                                     !0
          9        DO_ICALL                                             $8      
         10      > FE_RESET_R                                           $9      $8, ->33
         11    > > FE_FETCH_R                                                   $9, !2, ->33
   10    12    >   INIT_FCALL_BY_NAME                                           'find_paths'
         13        SEND_VAR_EX                                                  !0
         14        DO_FCALL                                          0  $10     
         15      > FE_RESET_R                                           $11     $10, ->31
         16    > > FE_FETCH_R                                                   $11, !3, ->31
   11    17    >   INIT_FCALL                                                   'array_merge'
         18        INIT_ARRAY                                           ~13     !2
         19        SEND_VAL                                                     ~13
         20        TYPE_CHECK                                      128          !3
         21      > JMPZ                                                         ~14, ->24
         22    >   QM_ASSIGN                                            ~15     !3
         23      > JMP                                                          ->26
         24    >   INIT_ARRAY                                           ~16     !3
         25        QM_ASSIGN                                            ~15     ~16
         26    >   SEND_VAL                                                     ~15
         27        DO_ICALL                                             $17     
         28        ASSIGN_DIM                                                   !1
         29        OP_DATA                                                      $17
   10    30      > JMP                                                          ->16
         31    >   FE_FREE                                                      $11
    9    32      > JMP                                                          ->11
         33    >   FE_FREE                                                      $9
   14    34      > RETURN                                                       !1
   15    35*     > RETURN                                                       null

End of function find_paths

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.31 ms | 3073 KiB | 19 Q