3v4l.org

run code in 300+ PHP versions simultaneously
<?php function make_recursive($arr, $root = 0, $pid = 'pid', $id = 'id', $child = 'child') { $m = array(); foreach ($arr as $e) { if (!isset($m[$e[$pid]])) $m[$e[$pid]] = array(); if (!isset($m[$e[$id]])) $m[$e[$id]] = array(); $m[$e[$pid]][] = array_merge($e, array($child => &$m[$e[$id]])); } return $m[$root][0]; } $arr = array( array('id' => 5273, 'pid' => 0, 'name' => 'John Doe'), array('id' => 6032, 'pid' => 5273, 'name' => 'Sally Smith'), array('id' => 6034, 'pid' => 6032, 'name' => 'Mike Jones'), array('id' => 6035, 'pid' => 6034, 'name' => 'Jason Williams'), array('id' => 6036, 'pid' => 5273, 'name' => 'Sara Johnson'), array('id' => 6037, 'pid' => 5273, 'name' => 'Dave Wilson'), array('id' => 6038, 'pid' => 6037, 'name' => 'Amy Martin'), ); $re=make_recursive($arr); var_export($re);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Uq0O5
function name:  (null)
number of ops:  9
compiled vars:  !0 = $arr, !1 = $re
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, <array>
   22     1        INIT_FCALL                                               'make_recursive'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   23     5        INIT_FCALL                                               'var_export'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function make_recursive:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 34
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 34
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 15
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 22
Branch analysis from position: 15
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/Uq0O5
function name:  make_recursive
number of ops:  39
compiled vars:  !0 = $arr, !1 = $root, !2 = $pid, !3 = $id, !4 = $child, !5 = $m, !6 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      'pid'
          3        RECV_INIT                                        !3      'id'
          4        RECV_INIT                                        !4      'child'
    4     5        ASSIGN                                                   !5, <array>
    5     6      > FE_RESET_R                                       $8      !0, ->34
          7    > > FE_FETCH_R                                               $8, !6, ->34
    6     8    >   FETCH_DIM_R                                      ~9      !6, !2
          9        ISSET_ISEMPTY_DIM_OBJ                         0  ~10     !5, ~9
         10        BOOL_NOT                                         ~11     ~10
         11      > JMPZ                                                     ~11, ->15
         12    >   FETCH_DIM_R                                      ~12     !6, !2
         13        ASSIGN_DIM                                               !5, ~12
         14        OP_DATA                                                  <array>
    7    15    >   FETCH_DIM_R                                      ~14     !6, !3
         16        ISSET_ISEMPTY_DIM_OBJ                         0  ~15     !5, ~14
         17        BOOL_NOT                                         ~16     ~15
         18      > JMPZ                                                     ~16, ->22
         19    >   FETCH_DIM_R                                      ~17     !6, !3
         20        ASSIGN_DIM                                               !5, ~17
         21        OP_DATA                                                  <array>
    8    22    >   FETCH_DIM_R                                      ~19     !6, !2
         23        INIT_FCALL                                               'array_merge'
         24        SEND_VAR                                                 !6
         25        FETCH_DIM_R                                      ~22     !6, !3
         26        FETCH_DIM_W                                      $23     !5, ~22
         27        INIT_ARRAY                                       ~24     $23, !4
         28        SEND_VAL                                                 ~24
         29        DO_ICALL                                         $25     
         30        FETCH_DIM_W                                      $20     !5, ~19
         31        ASSIGN_DIM                                               $20
         32        OP_DATA                                                  $25
    5    33      > JMP                                                      ->7
         34    >   FE_FREE                                                  $8
   10    35        FETCH_DIM_R                                      ~26     !5, !1
         36        FETCH_DIM_R                                      ~27     ~26, 0
         37      > RETURN                                                   ~27
   11    38*     > RETURN                                                   null

End of function make_recursive

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.04 ms | 1403 KiB | 18 Q