3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array( 3 => [4095, 651], 4095 => [3], 651 => [4432], 4432 => [3, 651], 92 => [45], 45 => [92], ); function getChildren($ind_ar,$prev_ar,$data, $rem){ $tmp = []; $mark = 0; foreach($ind_ar as $ind){ foreach($data[$ind] as $new_val){ if(!in_array($new_val,$prev_ar) && $new_val != $ind && $new_val != $rem){ $mark = 1; $tmp[] = $new_val; } foreach($data[$new_val] as $new){ if(!in_array($new,$prev_ar) && $new != $ind && $new != $rem){ $mark = 1; $tmp[] = $new; } } } } $res_ar = $prev_ar; if(!empty($tmp)) $res_ar = array_unique(array_merge($tmp,$prev_ar)); if($mark) $res_ar = getChildren($tmp,$res_ar,$data, $rem); return $res_ar; } foreach($data as $in => &$data_val) { $data_val = getChildren([$in],$data_val,$data, $in); sort($data_val); } print_r($data);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 16
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/hBs85
function name:  (null)
number of ops:  21
compiled vars:  !0 = $data, !1 = $data_val, !2 = $in
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   37     1      > FE_RESET_RW                                      $4      !0, ->16
          2    > > FE_FETCH_RW                                      ~5      $4, !1, ->16
          3    >   ASSIGN                                                   !2, ~5
   38     4        INIT_FCALL                                               'getchildren'
          5        INIT_ARRAY                                       ~7      !2
          6        SEND_VAL                                                 ~7
          7        SEND_VAR                                                 !1
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !2
         10        DO_FCALL                                      0  $8      
         11        ASSIGN                                                   !1, $8
   39    12        INIT_FCALL                                               'sort'
         13        SEND_REF                                                 !1
         14        DO_ICALL                                                 
   37    15      > JMP                                                      ->2
         16    >   FE_FREE                                                  $4
   42    17        INIT_FCALL                                               'print_r'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                                 
         20      > RETURN                                                   1

Function getchildren:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 49
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 49
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 47
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 47
Branch analysis from position: 11
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 46) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 26
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 45
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 45
Branch analysis from position: 29
2 jumps found. (Code = 46) Position 1 = 35, Position 2 = 37
Branch analysis from position: 35
2 jumps found. (Code = 46) Position 1 = 38, Position 2 = 40
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 44
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 44
Branch analysis from position: 40
Branch analysis from position: 37
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 45
Branch analysis from position: 26
Branch analysis from position: 22
Branch analysis from position: 19
Branch analysis from position: 47
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 47
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 62
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 70
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 70
Branch analysis from position: 62
Branch analysis from position: 49
filename:       /in/hBs85
function name:  getChildren
number of ops:  72
compiled vars:  !0 = $ind_ar, !1 = $prev_ar, !2 = $data, !3 = $rem, !4 = $tmp, !5 = $mark, !6 = $ind, !7 = $new_val, !8 = $new, !9 = $res_ar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
          3        RECV                                             !3      
    7     4        ASSIGN                                                   !4, <array>
    8     5        ASSIGN                                                   !5, 0
    9     6      > FE_RESET_R                                       $12     !0, ->49
          7    > > FE_FETCH_R                                               $12, !6, ->49
   11     8    >   FETCH_DIM_R                                      ~13     !2, !6
          9      > FE_RESET_R                                       $14     ~13, ->47
         10    > > FE_FETCH_R                                               $14, !7, ->47
   13    11    >   INIT_FCALL                                               'in_array'
         12        SEND_VAR                                                 !7
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $15     
         15        BOOL_NOT                                         ~16     $15
         16      > JMPZ_EX                                          ~16     ~16, ->19
         17    >   IS_NOT_EQUAL                                     ~17     !7, !6
         18        BOOL                                             ~16     ~17
         19    > > JMPZ_EX                                          ~16     ~16, ->22
         20    >   IS_NOT_EQUAL                                     ~18     !7, !3
         21        BOOL                                             ~16     ~18
         22    > > JMPZ                                                     ~16, ->26
   15    23    >   ASSIGN                                                   !5, 1
   16    24        ASSIGN_DIM                                               !4
         25        OP_DATA                                                  !7
   19    26    >   FETCH_DIM_R                                      ~21     !2, !7
         27      > FE_RESET_R                                       $22     ~21, ->45
         28    > > FE_FETCH_R                                               $22, !8, ->45
   20    29    >   INIT_FCALL                                               'in_array'
         30        SEND_VAR                                                 !8
         31        SEND_VAR                                                 !1
         32        DO_ICALL                                         $23     
         33        BOOL_NOT                                         ~24     $23
         34      > JMPZ_EX                                          ~24     ~24, ->37
         35    >   IS_NOT_EQUAL                                     ~25     !8, !6
         36        BOOL                                             ~24     ~25
         37    > > JMPZ_EX                                          ~24     ~24, ->40
         38    >   IS_NOT_EQUAL                                     ~26     !8, !3
         39        BOOL                                             ~24     ~26
         40    > > JMPZ                                                     ~24, ->44
   22    41    >   ASSIGN                                                   !5, 1
   23    42        ASSIGN_DIM                                               !4
         43        OP_DATA                                                  !8
   19    44    > > JMP                                                      ->28
         45    >   FE_FREE                                                  $22
   11    46      > JMP                                                      ->10
         47    >   FE_FREE                                                  $14
    9    48      > JMP                                                      ->7
         49    >   FE_FREE                                                  $12
   29    50        ASSIGN                                                   !9, !1
   31    51        ISSET_ISEMPTY_CV                                 ~30     !4
         52        BOOL_NOT                                         ~31     ~30
         53      > JMPZ                                                     ~31, ->62
         54    >   INIT_FCALL                                               'array_unique'
         55        INIT_FCALL                                               'array_merge'
         56        SEND_VAR                                                 !4
         57        SEND_VAR                                                 !1
         58        DO_ICALL                                         $32     
         59        SEND_VAR                                                 $32
         60        DO_ICALL                                         $33     
         61        ASSIGN                                                   !9, $33
   32    62    > > JMPZ                                                     !5, ->70
         63    >   INIT_FCALL_BY_NAME                                       'getChildren'
         64        SEND_VAR_EX                                              !4
         65        SEND_VAR_EX                                              !9
         66        SEND_VAR_EX                                              !2
         67        SEND_VAR_EX                                              !3
         68        DO_FCALL                                      0  $35     
         69        ASSIGN                                                   !9, $35
   34    70    > > RETURN                                                   !9
   35    71*     > RETURN                                                   null

End of function getchildren

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142 ms | 1085 KiB | 19 Q