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) { $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/GQ2AR
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>
   73     1        NEW                                              $4      'Tree'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !1, $4
   74     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
   75     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/GQ2AR
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 = 8, Position 2 = 11
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 11
filename:       /in/GQ2AR
function name:  process
number of ops:  21
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        FETCH_DIM_R                                      ~4      !1, 'text'
          3        FETCH_OBJ_W                                      $2      'html'
          4        ASSIGN_DIM                                               $2, !0
          5        OP_DATA                                                  ~4
   65     6        ARRAY_KEY_EXISTS                                 ~5      'children', !1
          7      > JMPZ_EX                                          ~5      ~5, ->11
          8    >   FETCH_DIM_R                                      ~6      !1, 'children'
          9        COUNT                                            ~7      ~6
         10        BOOL                                             ~5      ~7
         11    > > JMPZ                                                     ~5, ->20
   66    12    >   FETCH_OBJ_RW                                     $8      'html'
         13        ASSIGN_DIM_OP                .=               8          $8, !0
         14        OP_DATA                                                  '%2F'
   67    15        INIT_METHOD_CALL                                         'process'
         16        SEND_VAR                                                 !0
         17        FETCH_DIM_R                                      ~10     !1, 'children'
         18        SEND_VAL                                                 ~10
         19        DO_FCALL                                      0          
   69    20    > > RETURN                                                   null

End of function process

End of class Tree.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
166.01 ms | 1400 KiB | 15 Q