3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a=array(array(207306,'Bob',''), array (199730,'Sam',199714), array(199728,'Simon',207306), array(199714,'John',207306), array(199716,'Tom',199718), array(199718,'Phillip',207306), array(199720,'James',207306)); # map the children by parent $parents = ['' => []]; foreach ($a as $val) { $parents[$val[2]][] = $val; } # start with those with no parent $sorted = $parents['']; # add the children the current nodes are parent of until the array is empty # a bit slower loop which works in all versions for ($val = reset($sorted); $val; $val = next($sorted)) { if (isset($parents[$val[0]])) { foreach ($parents[$val[0]] as $next) { $sorted[] = $next; } } } var_dump($sorted);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 9
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 17
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 28
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 27
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 27
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 17
Branch analysis from position: 33
Branch analysis from position: 17
Branch analysis from position: 27
Branch analysis from position: 28
Branch analysis from position: 9
filename:       /in/Uk6Gs
function name:  (null)
number of ops:  37
compiled vars:  !0 = $a, !1 = $parents, !2 = $val, !3 = $sorted, !4 = $next
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   11     1        ASSIGN                                                   !1, <array>
   12     2      > FE_RESET_R                                       $7      !0, ->9
          3    > > FE_FETCH_R                                               $7, !2, ->9
   13     4    >   FETCH_DIM_R                                      ~8      !2, 2
          5        FETCH_DIM_W                                      $9      !1, ~8
          6        ASSIGN_DIM                                               $9
          7        OP_DATA                                                  !2
   12     8      > JMP                                                      ->3
          9    >   FE_FREE                                                  $7
   16    10        FETCH_DIM_R                                      ~11     !1, ''
         11        ASSIGN                                                   !3, ~11
   20    12        INIT_FCALL                                               'reset'
         13        SEND_REF                                                 !3
         14        DO_ICALL                                         $13     
         15        ASSIGN                                                   !2, $13
         16      > JMP                                                      ->32
   21    17    >   FETCH_DIM_R                                      ~15     !2, 0
         18        ISSET_ISEMPTY_DIM_OBJ                         0          !1, ~15
         19      > JMPZ                                                     ~16, ->28
   22    20    >   FETCH_DIM_R                                      ~17     !2, 0
         21        FETCH_DIM_R                                      ~18     !1, ~17
         22      > FE_RESET_R                                       $19     ~18, ->27
         23    > > FE_FETCH_R                                               $19, !4, ->27
   23    24    >   ASSIGN_DIM                                               !3
         25        OP_DATA                                                  !4
   22    26      > JMP                                                      ->23
         27    >   FE_FREE                                                  $19
   20    28    >   INIT_FCALL                                               'next'
         29        SEND_REF                                                 !3
         30        DO_ICALL                                         $21     
         31        ASSIGN                                                   !2, $21
         32    > > JMPNZ                                                    !2, ->17
   28    33    >   INIT_FCALL                                               'var_dump'
         34        SEND_VAR                                                 !3
         35        DO_ICALL                                                 
         36      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
180.78 ms | 1400 KiB | 19 Q