3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 0 => array( "text" => "eventyrer", "children"=> array( 4 => array( "text" => "news", "children"=> array( 1=> array("text"=>"a") ) ), 5 => array( "text" => "nyheter", "children"=> array( 1=> array("text"=>"b") ) ) ) ), 1 => array( "text" => "eventyrer2017", "children"=> array( 6 => array( "text" => "news", "children"=> array( 1=> array("text"=>"c") ) ), 8 => array( "text" => "nyheter", "children"=> array( 1=> array("text"=>"d") ) ) ) ) ); class Tree { private $data; private $html; public function buildTree(array $data, $parent_id) { $this->data = $data; $this->html = []; foreach ($data as $key => $value) { $this->process($key, $value); } return $this->html; } private function process($parentKey, $value) { var_dump($value); $this->html[$parentKey] = $value['text']; if (array_key_exists('children', $value) && count($value['children'])) { $this->html[$parentKey] .= '/'; $this->process($parentKey, $value['children']); } } } $tree = new Tree(); $ul = $tree->buildTree($arr, 0); var_dump( $ul);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eViFa
function name:  (null)
number of ops:  13
compiled vars:  !0 = $arr, !1 = $tree, !2 = $ul
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   74     1        NEW                                              $4      'Tree'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $4
   75     4        INIT_METHOD_CALL                                         !1, 'buildTree'
          5        SEND_VAR_EX                                              !0
          6        SEND_VAL_EX                                              0
          7        DO_FCALL                                      0  $7      
          8        ASSIGN                                                   !2, $7
   76     9        INIT_FCALL                                               'var_dump'
         10        SEND_VAR                                                 !2
         11        DO_ICALL                                                 
         12      > RETURN                                                   1

Class Tree:
Function buildtree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 14
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/eViFa
function name:  buildTree
number of ops:  18
compiled vars:  !0 = $data, !1 = $parent_id, !2 = $value, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   53     2        ASSIGN_OBJ                                               'data'
          3        OP_DATA                                                  !0
   54     4        ASSIGN_OBJ                                               'html'
          5        OP_DATA                                                  <array>
   55     6      > FE_RESET_R                                       $6      !0, ->14
          7    > > FE_FETCH_R                                       ~7      $6, !2, ->14
          8    >   ASSIGN                                                   !3, ~7
   56     9        INIT_METHOD_CALL                                         'process'
         10        SEND_VAR_EX                                              !3
         11        SEND_VAR_EX                                              !2
         12        DO_FCALL                                      0          
   55    13      > JMP                                                      ->7
         14    >   FE_FREE                                                  $6
   59    15        FETCH_OBJ_R                                      ~10     'html'
         16      > RETURN                                                   ~10
   60    17*     > RETURN                                                   null

End of function buildtree

Function process:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
Branch analysis from position: 14
filename:       /in/eViFa
function name:  process
number of ops:  24
compiled vars:  !0 = $parentKey, !1 = $value
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   62     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   64     2        INIT_FCALL                                               'var_dump'
          3        SEND_VAR                                                 !1
          4        DO_ICALL                                                 
   65     5        FETCH_DIM_R                                      ~5      !1, 'text'
          6        FETCH_OBJ_W                                      $3      'html'
          7        ASSIGN_DIM                                               $3, !0
          8        OP_DATA                                                  ~5
   66     9        ARRAY_KEY_EXISTS                                 ~6      'children', !1
         10      > JMPZ_EX                                          ~6      ~6, ->14
         11    >   FETCH_DIM_R                                      ~7      !1, 'children'
         12        COUNT                                            ~8      ~7
         13        BOOL                                             ~6      ~8
         14    > > JMPZ                                                     ~6, ->23
   67    15    >   FETCH_OBJ_RW                                     $9      'html'
         16        ASSIGN_DIM_OP                .=               8          $9, !0
         17        OP_DATA                                                  '%2F'
   68    18        INIT_METHOD_CALL                                         'process'
         19        SEND_VAR                                                 !0
         20        FETCH_DIM_R                                      ~11     !1, 'children'
         21        SEND_VAL                                                 ~11
         22        DO_FCALL                                      0          
   70    23    > > RETURN                                                   null

End of function process

End of class Tree.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.89 ms | 1400 KiB | 15 Q