3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ (object)['Dep_name' => 'Accounting and Finance', 'dep_id' => 1, 'dep_parent_id' => 0], (object)['Dep_name' => 'Human-Recources', 'dep_id' => 2, 'dep_parent_id' => 0], (object)['Dep_name' => 'IT', 'dep_id' => 3, 'dep_parent_id' => 0, 'children' => [ (object)['Dep_name' => 'Network', 'dep_id' => 5, 'dep_parent_id' => 3], (object)['Dep_name' => 'Web Development', 'dep_id' => 6, 'dep_parent_id' => 3, 'children' => [ (object)['Dep_name' => 'Front-End', 'dep_id' => 7, 'dep_parent_id' => 6], (object)['Dep_name' => 'Back-End', 'dep_id' => 7, 'dep_parent_id' => 6], ] ], ] ], (object)['Dep_name' => 'Marketing', 'dep_id' => 4, 'dep_parent_id' => 0, 'children' => [ (object)['Dep_name' => 'web-marketing', 'dep_id' => 9, 'dep_parent_id' => 4], ] ] ]; function printTree($array) { $output = "<ul>\n"; foreach ($array as $a) { $output .= "<li>".$a->Dep_name."</li>\n"; if (isset($a->children)) { $output .= printTree($a->children); } } $output .= "</ul>\n"; return $output; } echo printTree($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QUtVj
function name:  (null)
number of ops:  36
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   CAST                                          8  ~1      <array>
          1        INIT_ARRAY                                       ~2      ~1
    5     2        CAST                                          8  ~3      <array>
          3        ADD_ARRAY_ELEMENT                                ~2      ~3
    6     4        INIT_ARRAY                                       ~4      'IT', 'Dep_name'
          5        ADD_ARRAY_ELEMENT                                ~4      3, 'dep_id'
          6        ADD_ARRAY_ELEMENT                                ~4      0, 'dep_parent_id'
    7     7        CAST                                          8  ~5      <array>
          8        INIT_ARRAY                                       ~6      ~5
    8     9        INIT_ARRAY                                       ~7      'Web+Development', 'Dep_name'
         10        ADD_ARRAY_ELEMENT                                ~7      6, 'dep_id'
         11        ADD_ARRAY_ELEMENT                                ~7      3, 'dep_parent_id'
    9    12        CAST                                          8  ~8      <array>
         13        INIT_ARRAY                                       ~9      ~8
   10    14        CAST                                          8  ~10     <array>
         15        ADD_ARRAY_ELEMENT                                ~9      ~10
         16        ADD_ARRAY_ELEMENT                                ~7      ~9, 'children'
         17        CAST                                          8  ~11     ~7
         18        ADD_ARRAY_ELEMENT                                ~6      ~11
         19        ADD_ARRAY_ELEMENT                                ~4      ~6, 'children'
         20        CAST                                          8  ~12     ~4
         21        ADD_ARRAY_ELEMENT                                ~2      ~12
   15    22        INIT_ARRAY                                       ~13     'Marketing', 'Dep_name'
         23        ADD_ARRAY_ELEMENT                                ~13     4, 'dep_id'
         24        ADD_ARRAY_ELEMENT                                ~13     0, 'dep_parent_id'
   16    25        CAST                                          8  ~14     <array>
         26        INIT_ARRAY                                       ~15     ~14
         27        ADD_ARRAY_ELEMENT                                ~13     ~15, 'children'
         28        CAST                                          8  ~16     ~13
         29        ADD_ARRAY_ELEMENT                                ~2      ~16
    3    30        ASSIGN                                                   !0, ~2
   33    31        INIT_FCALL                                               'printtree'
         32        SEND_VAR                                                 !0
         33        DO_FCALL                                      0  $18     
         34        ECHO                                                     $18
         35      > RETURN                                                   1

Function printtree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 17
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 17
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 16
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/QUtVj
function name:  printTree
number of ops:  21
compiled vars:  !0 = $array, !1 = $output, !2 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
   22     1        ASSIGN                                                   !1, '%3Cul%3E%0A'
   23     2      > FE_RESET_R                                       $4      !0, ->17
          3    > > FE_FETCH_R                                               $4, !2, ->17
   24     4    >   FETCH_OBJ_R                                      ~5      !2, 'Dep_name'
          5        CONCAT                                           ~6      '%3Cli%3E', ~5
          6        CONCAT                                           ~7      ~6, '%3C%2Fli%3E%0A'
          7        ASSIGN_OP                                     8          !1, ~7
   26     8        ISSET_ISEMPTY_PROP_OBJ                                   !2, 'children'
          9      > JMPZ                                                     ~9, ->16
   27    10    >   INIT_FCALL_BY_NAME                                       'printTree'
         11        CHECK_FUNC_ARG                                           
         12        FETCH_OBJ_FUNC_ARG                               $10     !2, 'children'
         13        SEND_FUNC_ARG                                            $10
         14        DO_FCALL                                      0  $11     
         15        ASSIGN_OP                                     8          !1, $11
   23    16    > > JMP                                                      ->3
         17    >   FE_FREE                                                  $4
   30    18        ASSIGN_OP                                     8          !1, '%3C%2Ful%3E%0A'
   31    19      > RETURN                                                   !1
   32    20*     > RETURN                                                   null

End of function printtree

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
126.65 ms | 1407 KiB | 14 Q