3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* assuming top level pid = 0 */$rows = array ( array ( 'id' => 1, 'pid' => 0 ), array ( 'id' => 2, 'pid' => 1 ), array ( 'id' => 3, 'pid' => 2 ), array ( 'id' => 4, 'pid' => 0 ), array ( 'id' => 5, 'pid' => 4 ), /* ... */);$rows = array_column ( $rows, null, 'id' );foreach ( $rows as $key => $val ) { if ( $val ['pid'] ) { if ( isset ( $rows [$val ['pid']] )) { $rows [$val ['pid']]['children'][] = &$rows [$key]; } }}foreach ( $rows as $key => $val ) { if ( $val ['pid'] ) unset ( $rows [$key] );}var_dump ( $rows );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 23
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 23
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 22
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 22
Branch analysis from position: 22
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 31
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 30
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 30
Branch analysis from position: 31
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 31
Branch analysis from position: 23
filename:       /in/vm6PF
function name:  (null)
number of ops:  36
compiled vars:  !0 = $rows, !1 = $val, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
          1        INIT_FCALL                                               'array_column'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 null
          4        SEND_VAL                                                 'id'
          5        DO_ICALL                                         $4      
          6        ASSIGN                                                   !0, $4
          7      > FE_RESET_R                                       $6      !0, ->23
          8    > > FE_FETCH_R                                       ~7      $6, !1, ->23
          9    >   ASSIGN                                                   !2, ~7
         10        FETCH_DIM_R                                      ~9      !1, 'pid'
         11      > JMPZ                                                     ~9, ->22
         12    >   FETCH_DIM_R                                      ~10     !1, 'pid'
         13        ISSET_ISEMPTY_DIM_OBJ                         0          !0, ~10
         14      > JMPZ                                                     ~11, ->22
         15    >   FETCH_DIM_R                                      ~12     !1, 'pid'
         16        FETCH_DIM_W                                      $16     !0, !2
         17        MAKE_REF                                         $17     $16
         18        FETCH_DIM_W                                      $13     !0, ~12
         19        FETCH_DIM_W                                      $14     $13, 'children'
         20        FETCH_DIM_W                                      $15     $14
         21        ASSIGN_REF                                               $15, $17
         22    > > JMP                                                      ->8
         23    >   FE_FREE                                                  $6
         24      > FE_RESET_R                                       $19     !0, ->31
         25    > > FE_FETCH_R                                       ~20     $19, !1, ->31
         26    >   ASSIGN                                                   !2, ~20
         27        FETCH_DIM_R                                      ~22     !1, 'pid'
         28      > JMPZ                                                     ~22, ->30
         29    >   UNSET_DIM                                                !0, !2
         30    > > JMP                                                      ->25
         31    >   FE_FREE                                                  $19
         32        INIT_FCALL                                               'var_dump'
         33        SEND_VAR                                                 !0
         34        DO_ICALL                                                 
         35      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.73 ms | 1392 KiB | 17 Q