3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = array( 55 => array( 'ident' => 'test 1', 'depth' => 1, ), 77 => array( 'parent_id' => 55, 'ident' => 'test 2', 'depth' => 2, ), 109 => array( 'parent_id' => 77, 'ident' => 'test 3', 'depth' => 3, ), 78 => array( 'parent_id' => 55, 'ident' => 'test 4', 'depth' => 2, ), 25 => array( 'ident' => 'test 5', 'depth' => 1, ) ); foreach ($array as $key => &$sub) { if (isset($sub['parent_id'])) { $array[$sub['parent_id']]['children'][$key] = &$sub; } } unset($sub); // unset the reference to make sure to not overwrite it later... // now remove the entries with parents foreach ($array as $key => $sub) { if (isset($sub['parent_id'])) unset($array[$key]); } var_dump($array);
Finding entry points
Branch analysis from position: 0
Jump found. Position 1 = 2, Position 2 = 12
Branch analysis from position: 2
Jump found. Position 1 = 3, Position 2 = 12
Branch analysis from position: 3
Jump found. Position 1 = 6, Position 2 = 11
Branch analysis from position: 6
Jump found. Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 11
Branch analysis from position: 12
Jump found. Position 1 = 15, Position 2 = 21
Branch analysis from position: 15
Jump found. Position 1 = 16, Position 2 = 21
Branch analysis from position: 16
Jump found. Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
Jump found. Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 20
Branch analysis from position: 21
Jump found. Position 1 = -2
Branch analysis from position: 21
Branch analysis from position: 12
filename:       /in/D6l6U
function name:  (null)
number of ops:  26
compiled vars:  !0 = $array, !1 = $sub, !2 = $key
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   7     0  E >   ASSIGN                                                   !0, <array>
  28     1      > FE_RESET_RW                                      $4      !0, ->12
         2    > > FE_FETCH_RW                                      ~5      $4, !1, ->12
         3    >   ASSIGN                                                   !2, ~5
  29     4        ISSET_ISEMPTY_DIM_OBJ                       33554432  ~7      !1, 'parent_id'
         5      > JMPZ                                                     ~7, ->11
  30     6    >   FETCH_DIM_R                                      $8      !1, 'parent_id'
         7        FETCH_DIM_W                                      $9      !0, $8
         8        FETCH_DIM_W                                      $10     $9, 'children'
         9        FETCH_DIM_W                                      $11     $10, !2
        10        ASSIGN_REF                                               $11, !1
        11    > > JMP                                                      ->2
        12    >   FE_FREE                                                  $4
  33    13        UNSET_VAR                                                !1
  36    14      > FE_RESET_R                                       $13     !0, ->21
        15    > > FE_FETCH_R                                       ~14     $13, !1, ->21
        16    >   ASSIGN                                                   !2, ~14
  37    17        ISSET_ISEMPTY_DIM_OBJ                       33554432  ~16     !1, 'parent_id'
        18      > JMPZ                                                     ~16, ->20
  38    19    >   UNSET_DIM                                                !0, !2
        20    > > JMP                                                      ->15
        21    >   FE_FREE                                                  $13
  40    22        INIT_FCALL                                               'var_dump'
        23        SEND_VAR                                                 !0
        24        DO_ICALL                                                 
        25      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 7.3.0