3v4l.org

run code in 300+ PHP versions simultaneously
<?php $belongGroup = [ 2, 1 ]; $groups = [ 1 => ['parent_group_id' => 0, 'group_id' => 1], 2 => ['parent_group_id' => 1, 'group_id' => 2], 3 => ['parent_group_id' => 0, 'group_id' => 3], 4 => ['parent_group_id' => 0, 'group_id' => 4], ]; $result = []; foreach($belongGroup as $g) { $l = $groups[$g]; var_dump($l); while(true) { echo $l['parent_group_id'] == 0; if ($l['parent_group_id'] == 0) { break; } $parentId = $l['parent_group_id']; $l = $groups[$parentId]; unset($groups[$parentId]); } $result[] = intval($l['group_id']); } echo implode(", ", $result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 29
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 29
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 11
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 11
Branch analysis from position: 24
Branch analysis from position: 11
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
filename:       /in/3nUVo
function name:  (null)
number of ops:  36
compiled vars:  !0 = $belongGroup, !1 = $groups, !2 = $result, !3 = $g, !4 = $l, !5 = $parentId
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    7     1        ASSIGN                                                   !1, <array>
   14     2        ASSIGN                                                   !2, <array>
   15     3      > FE_RESET_R                                       $9      !0, ->29
          4    > > FE_FETCH_R                                               $9, !3, ->29
   16     5    >   FETCH_DIM_R                                      ~10     !1, !3
          6        ASSIGN                                                   !4, ~10
   17     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !4
          9        DO_ICALL                                                 
   18    10      > JMP                                                      ->23
   19    11    >   FETCH_DIM_R                                      ~13     !4, 'parent_group_id'
         12        IS_EQUAL                                         ~14     ~13, 0
         13        ECHO                                                     ~14
   20    14        FETCH_DIM_R                                      ~15     !4, 'parent_group_id'
         15        IS_EQUAL                                                 ~15, 0
         16      > JMPZ                                                     ~16, ->18
   21    17    > > JMP                                                      ->24
   23    18    >   FETCH_DIM_R                                      ~17     !4, 'parent_group_id'
         19        ASSIGN                                                   !5, ~17
   24    20        FETCH_DIM_R                                      ~19     !1, !5
         21        ASSIGN                                                   !4, ~19
   25    22        UNSET_DIM                                                !1, !5
   18    23    > > JMPNZ                                                    <true>, ->11
   27    24    >   FETCH_DIM_R                                      ~22     !4, 'group_id'
         25        CAST                                          4  ~23     ~22
         26        ASSIGN_DIM                                               !2
         27        OP_DATA                                                  ~23
   15    28      > JMP                                                      ->4
         29    >   FE_FREE                                                  $9
   30    30        INIT_FCALL                                               'implode'
         31        SEND_VAL                                                 '%2C+'
         32        SEND_VAR                                                 !2
         33        DO_ICALL                                         $24     
         34        ECHO                                                     $24
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
176.24 ms | 1400 KiB | 17 Q