3v4l.org

run code in 300+ PHP versions simultaneously
<?php // result from query: SELECT * FROM depts $depts = array( array( // row #0 'deptid' => 1, 'dept_code' => '1', 'dept_name' => 'wadir Umum', 'parent_deptid' => 0, ), array( // row #1 'deptid' => 2, 'dept_code' => '101', 'dept_name' => 'bagian umum', 'parent_deptid' => 1, ), array( // row #2 'deptid' => 3, 'dept_code' => '10101', 'dept_name' => 'kepala umum', 'parent_deptid' => 2, ), array( // row #3 'deptid' => 4, 'dept_code' => '102', 'dept_name' => 'bagian privasi', 'parent_deptid' => 1, ), array( // row #4 'deptid' => 5, 'dept_code' => '1010101', 'dept_name' => 'SUb bagian Tu', 'parent_deptid' => 3, ), array( // row #5 'deptid' => 6, 'dept_code' => '1010102', 'dept_name' => 'bagian umum', 'parent_deptid' => 3, ), ); $nodes = array(); $roots = array(); // init nodes foreach ($depts as $dept) { $dept['childs'] = array(); // init childs $nodes[$dept['deptid']] = $dept; } foreach ($depts as $dept) { if ($dept['parent_deptid'] == 0) { $roots[] = $dept['deptid']; // add root } else { $nodes[$dept['parent_deptid']]['childs'][] = $dept['deptid']; // add to parents chlids list } } function getSubtreeHTMLList($deptsids, $nodes) { $result = '<ul>'; foreach ($deptsids as $deptsid) { $result .= '<li>'; $result .= $nodes[$deptsid]['dept_name']; if (count($nodes[$deptsid]['childs'] > 0)) { $result .= getSubtreeHTMLList($nodes[$deptsid]['childs'], $nodes); } $result .= '</li>'; } $result .= '</ul>'; return $result; } echo getSubtreeHTMLList($roots, $nodes); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 28
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 28
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 21
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 28
Branch analysis from position: 11
filename:       /in/mnV5m
function name:  (null)
number of ops:  35
compiled vars:  !0 = $depts, !1 = $nodes, !2 = $roots, !3 = $dept
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   44     1        ASSIGN                                                   !1, <array>
   45     2        ASSIGN                                                   !2, <array>
   48     3      > FE_RESET_R                                       $7      !0, ->11
          4    > > FE_FETCH_R                                               $7, !3, ->11
   49     5    >   ASSIGN_DIM                                               !3, 'childs'
          6        OP_DATA                                                  <array>
   50     7        FETCH_DIM_R                                      ~9      !3, 'deptid'
          8        ASSIGN_DIM                                               !1, ~9
          9        OP_DATA                                                  !3
   48    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $7
   54    12      > FE_RESET_R                                       $11     !0, ->28
         13    > > FE_FETCH_R                                               $11, !3, ->28
   55    14    >   FETCH_DIM_R                                      ~12     !3, 'parent_deptid'
         15        IS_EQUAL                                                 ~12, 0
         16      > JMPZ                                                     ~13, ->21
   56    17    >   FETCH_DIM_R                                      ~15     !3, 'deptid'
         18        ASSIGN_DIM                                               !2
         19        OP_DATA                                                  ~15
   55    20      > JMP                                                      ->27
   58    21    >   FETCH_DIM_R                                      ~16     !3, 'parent_deptid'
         22        FETCH_DIM_R                                      ~20     !3, 'deptid'
         23        FETCH_DIM_W                                      $17     !1, ~16
         24        FETCH_DIM_W                                      $18     $17, 'childs'
         25        ASSIGN_DIM                                               $18
         26        OP_DATA                                                  ~20
   54    27    > > JMP                                                      ->13
         28    >   FE_FREE                                                  $11
   76    29        INIT_FCALL                                               'getsubtreehtmllist'
         30        SEND_VAR                                                 !2
         31        SEND_VAR                                                 !1
         32        DO_FCALL                                      0  $21     
         33        ECHO                                                     $21
   78    34      > RETURN                                                   1

Function getsubtreehtmllist:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 24
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 24
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 22
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/mnV5m
function name:  getSubtreeHTMLList
number of ops:  28
compiled vars:  !0 = $deptsids, !1 = $nodes, !2 = $result, !3 = $deptsid
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   63     2        ASSIGN                                                   !2, '%3Cul%3E'
   64     3      > FE_RESET_R                                       $5      !0, ->24
          4    > > FE_FETCH_R                                               $5, !3, ->24
   65     5    >   ASSIGN_OP                                     8          !2, '%3Cli%3E'
   66     6        FETCH_DIM_R                                      ~7      !1, !3
          7        FETCH_DIM_R                                      ~8      ~7, 'dept_name'
          8        ASSIGN_OP                                     8          !2, ~8
   67     9        FETCH_DIM_R                                      ~10     !1, !3
         10        FETCH_DIM_R                                      ~11     ~10, 'childs'
         11        IS_SMALLER                                       ~12     0, ~11
         12        COUNT                                            ~13     ~12
         13      > JMPZ                                                     ~13, ->22
   68    14    >   INIT_FCALL_BY_NAME                                       'getSubtreeHTMLList'
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $14     !1, !3
         17        FETCH_DIM_FUNC_ARG                               $15     $14, 'childs'
         18        SEND_FUNC_ARG                                            $15
         19        SEND_VAR_EX                                              !1
         20        DO_FCALL                                      0  $16     
         21        ASSIGN_OP                                     8          !2, $16
   70    22    >   ASSIGN_OP                                     8          !2, '%3C%2Fli%3E'
   64    23      > JMP                                                      ->4
         24    >   FE_FREE                                                  $5
   72    25        ASSIGN_OP                                     8          !2, '%3C%2Ful%3E'
   73    26      > RETURN                                                   !2
   74    27*     > RETURN                                                   null

End of function getsubtreehtmllist

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.38 ms | 1003 KiB | 14 Q