3v4l.org

run code in 300+ PHP versions simultaneously
<style> ul{ list-style: none; } li { position: relative; margin-left: -15px; list-style: none; } </style><?php $arr = array ( '192.168.10.216' => '192.168.40.103', '192.168.10.217' => '192.168.10.216', '192.168.10.88' => '192.168.10.216', '192.168.40.102' => NULL, '192.168.40.103' => '192.168.40.102', '192.168.40.104' => '192.168.40.102' ); function parseTree($tree, $root = null) { $return = array(); # Traverse the tree and search for direct children of the root foreach($tree as $child => $parent) { # A direct child is found if($parent == $root) { # Remove item from tree (we don't need to traverse this again) unset($tree[$child]); # Append the child into result array and parse its children $return[] = array( 'name' => $child, 'children' => parseTree($tree, $child) ); } } return empty($return) ? null : $return; } function printtree($tree) { if(!is_null($tree) && count($tree) > 0) { echo '<ul>'; foreach($tree as $b) { echo '<li>'.$b['name']; printtree($b['children']); echo '</li>'; } echo '</ul>'; } } printtree(parseTree($arr));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/klKhd
function name:  (null)
number of ops:  9
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    1     0  E >   ECHO                                                     '%3Cstyle%3E%0Aul%7B%0A++list-style%3A+none%3B%0A%7D%0A%0A%0A++++li+%0A++++%7B+%0A++++++++position%3A+relative%3B+%0A++++++++margin-left%3A+-15px%3B%0A++++++++list-style%3A+none%3B%0A++++%7D%0A%3C%2Fstyle%3E'
   14     1        ASSIGN                                                   !0, <array>
   51     2        INIT_FCALL                                               'printtree'
          3        INIT_FCALL                                               'parsetree'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_FCALL                                      0          
          8      > RETURN                                                   1

Function parsetree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 18
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 17
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 23
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/klKhd
function name:  parseTree
number of ops:  26
compiled vars:  !0 = $tree, !1 = $root, !2 = $return, !3 = $parent, !4 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      null
   22     2        ASSIGN                                                   !2, <array>
   24     3      > FE_RESET_R                                       $6      !0, ->18
          4    > > FE_FETCH_R                                       ~7      $6, !3, ->18
          5    >   ASSIGN                                                   !4, ~7
   26     6        IS_EQUAL                                                 !3, !1
          7      > JMPZ                                                     ~9, ->17
   28     8    >   UNSET_DIM                                                !0, !4
   31     9        INIT_ARRAY                                       ~11     !4, 'name'
   32    10        INIT_FCALL_BY_NAME                                       'parseTree'
         11        SEND_VAR_EX                                              !0
         12        SEND_VAR_EX                                              !4
         13        DO_FCALL                                      0  $12     
         14        ADD_ARRAY_ELEMENT                                ~11     $12, 'children'
   30    15        ASSIGN_DIM                                               !2
   32    16        OP_DATA                                                  ~11
   24    17    > > JMP                                                      ->4
         18    >   FE_FREE                                                  $6
   36    19        ISSET_ISEMPTY_CV                                         !2
         20      > JMPZ                                                     ~13, ->23
         21    >   QM_ASSIGN                                        ~14     null
         22      > JMP                                                      ->24
         23    >   QM_ASSIGN                                        ~14     !2
         24    > > RETURN                                                   ~14
   37    25*     > RETURN                                                   null

End of function parsetree

Function printtree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 23
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 21
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 21
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
Branch analysis from position: 23
Branch analysis from position: 7
filename:       /in/klKhd
function name:  printtree
number of ops:  24
compiled vars:  !0 = $tree, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   40     1        TYPE_CHECK                                    2  ~2      !0
          2        BOOL_NOT                                         ~3      ~2
          3      > JMPZ_EX                                          ~3      ~3, ->7
          4    >   COUNT                                            ~4      !0
          5        IS_SMALLER                                       ~5      0, ~4
          6        BOOL                                             ~3      ~5
          7    > > JMPZ                                                     ~3, ->23
   41     8    >   ECHO                                                     '%3Cul%3E'
   42     9      > FE_RESET_R                                       $6      !0, ->21
         10    > > FE_FETCH_R                                               $6, !1, ->21
   43    11    >   FETCH_DIM_R                                      ~7      !1, 'name'
         12        CONCAT                                           ~8      '%3Cli%3E', ~7
         13        ECHO                                                     ~8
   44    14        INIT_FCALL_BY_NAME                                       'printtree'
         15        CHECK_FUNC_ARG                                           
         16        FETCH_DIM_FUNC_ARG                               $9      !1, 'children'
         17        SEND_FUNC_ARG                                            $9
         18        DO_FCALL                                      0          
   45    19        ECHO                                                     '%3C%2Fli%3E'
   42    20      > JMP                                                      ->10
         21    >   FE_FREE                                                  $6
   47    22        ECHO                                                     '%3C%2Ful%3E'
   49    23    > > RETURN                                                   null

End of function printtree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.3 ms | 1403 KiB | 15 Q