3v4l.org

run code in 300+ PHP versions simultaneously
<?php function find_parent($ar, $id='id', $pid='pid') { foreach($ar as $v) $t[$v[$id]] = $v; foreach ($t as $k => $item){ if( $item[$pid] ){ if( ! isset($t[$item[$pid]]['parent'][$item[$pid]]) ) $t[$item[$id]]['parent'][$item[$pid]] =& $t[$item[$pid]]; } } return $t; } function find_child($ar, $id='id', $pid='pid') { foreach($ar as $v) $t[$v[$id]] = $v; foreach ($t as $k => $item){ if( $item[$pid] ) { $t[$item[$pid]]['child'][$item[$id]] =& $t[$k]; } } return $t; } $data = array( array('ID'=>1, 'PARENT'=>0, 'NAME'=>'祖父'), array('ID'=>2, 'PARENT'=>1, 'NAME'=>'父亲'), array('ID'=>3, 'PARENT'=>1, 'NAME'=>'叔伯'), array('ID'=>4, 'PARENT'=>2, 'NAME'=>'自己'), array('ID'=>5, 'PARENT'=>4, 'NAME'=>'儿子'), ); $p = find_parent($data, 'ID', 'PARENT'); $c = find_child($data, 'ID', 'PARENT'); Print_r ($c);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WCW12
function name:  (null)
number of ops:  17
compiled vars:  !0 = $data, !1 = $p, !2 = $c
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, <array>
   34     1        INIT_FCALL                                               'find_parent'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 'ID'
          4        SEND_VAL                                                 'PARENT'
          5        DO_FCALL                                      0  $4      
          6        ASSIGN                                                   !1, $4
   35     7        INIT_FCALL                                               'find_child'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 'ID'
         10        SEND_VAL                                                 'PARENT'
         11        DO_FCALL                                      0  $6      
         12        ASSIGN                                                   !2, $6
   36    13        INIT_FCALL                                               'print_r'
         14        SEND_VAR                                                 !2
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function find_parent:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 32
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 32
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 31
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 31
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 31
Branch analysis from position: 31
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
Branch analysis from position: 9
filename:       /in/WCW12
function name:  find_parent
number of ops:  35
compiled vars:  !0 = $ar, !1 = $id, !2 = $pid, !3 = $v, !4 = $t, !5 = $item, !6 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'id'
          2        RECV_INIT                                        !2      'pid'
    4     3      > FE_RESET_R                                       $7      !0, ->9
          4    > > FE_FETCH_R                                               $7, !3, ->9
          5    >   FETCH_DIM_R                                      ~8      !3, !1
          6        ASSIGN_DIM                                               !4, ~8
          7        OP_DATA                                                  !3
          8      > JMP                                                      ->4
          9    >   FE_FREE                                                  $7
    5    10      > FE_RESET_R                                       $10     !4, ->32
         11    > > FE_FETCH_R                                       ~11     $10, !5, ->32
         12    >   ASSIGN                                                   !6, ~11
    6    13        FETCH_DIM_R                                      ~13     !5, !2
         14      > JMPZ                                                     ~13, ->31
    7    15    >   FETCH_DIM_R                                      ~14     !5, !2
         16        FETCH_DIM_R                                      ~17     !5, !2
         17        FETCH_DIM_IS                                     ~15     !4, ~14
         18        FETCH_DIM_IS                                     ~16     ~15, 'parent'
         19        ISSET_ISEMPTY_DIM_OBJ                         0  ~18     ~16, ~17
         20        BOOL_NOT                                         ~19     ~18
         21      > JMPZ                                                     ~19, ->31
    8    22    >   FETCH_DIM_R                                      ~20     !5, !1
         23        FETCH_DIM_R                                      ~23     !5, !2
         24        FETCH_DIM_R                                      ~25     !5, !2
         25        FETCH_DIM_W                                      $26     !4, ~25
         26        MAKE_REF                                         $27     $26
         27        FETCH_DIM_W                                      $21     !4, ~20
         28        FETCH_DIM_W                                      $22     $21, 'parent'
         29        FETCH_DIM_W                                      $24     $22, ~23
         30        ASSIGN_REF                                               $24, $27
    5    31    > > JMP                                                      ->11
         32    >   FE_FREE                                                  $10
   11    33      > RETURN                                                   !4
   12    34*     > RETURN                                                   null

End of function find_parent

Function find_child:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 9
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 9
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 24
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 23
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
Branch analysis from position: 9
filename:       /in/WCW12
function name:  find_child
number of ops:  27
compiled vars:  !0 = $ar, !1 = $id, !2 = $pid, !3 = $v, !4 = $t, !5 = $item, !6 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'id'
          2        RECV_INIT                                        !2      'pid'
   17     3      > FE_RESET_R                                       $7      !0, ->9
          4    > > FE_FETCH_R                                               $7, !3, ->9
          5    >   FETCH_DIM_R                                      ~8      !3, !1
          6        ASSIGN_DIM                                               !4, ~8
          7        OP_DATA                                                  !3
          8      > JMP                                                      ->4
          9    >   FE_FREE                                                  $7
   18    10      > FE_RESET_R                                       $10     !4, ->24
         11    > > FE_FETCH_R                                       ~11     $10, !5, ->24
         12    >   ASSIGN                                                   !6, ~11
   19    13        FETCH_DIM_R                                      ~13     !5, !2
         14      > JMPZ                                                     ~13, ->23
   20    15    >   FETCH_DIM_R                                      ~14     !5, !2
         16        FETCH_DIM_R                                      ~17     !5, !1
         17        FETCH_DIM_W                                      $19     !4, !6
         18        MAKE_REF                                         $20     $19
         19        FETCH_DIM_W                                      $15     !4, ~14
         20        FETCH_DIM_W                                      $16     $15, 'child'
         21        FETCH_DIM_W                                      $18     $16, ~17
         22        ASSIGN_REF                                               $18, $20
   18    23    > > JMP                                                      ->11
         24    >   FE_FREE                                                  $10
   23    25      > RETURN                                                   !4
   24    26*     > RETURN                                                   null

End of function find_child

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.19 ms | 1407 KiB | 17 Q