3v4l.org

run code in 300+ PHP versions simultaneously
<?php function page_walk($array, $parent_id = FALSE) { $organized_pages = array(); $children = array(); foreach($array as $index => $page) { if ( $page['parent_id'] == 0) // No, just spit it out and you're done { $organized_pages[$index] = $page; } else // If it does, { $organized_pages[$parent_id]['children'][$page['id']] = $this->page_walk($page, $parent_id); } } return $organized_pages; } function page_list($array) { $fakepages = array(); $fakepages[0] = array('id' => 1, 'parent_id' => 0, 'title' => 'Parent Page'); $fakepages[1] = array('id' => 2, 'parent_id' => 1, 'title' => 'Sub Page'); $fakepages[2] = array('id' => 3, 'parent_id' => 2, 'title' => 'Sub Sub Page'); $fakepages[3] = array('id' => 4, 'parent_id' => 3, 'title' => 'Another Parent Page'); $pages = $this->page_walk($fakepages, 0); print_r($pages); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GMJXg
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E > > RETURN                                                   1

Function page_walk:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 24
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 24
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 24
filename:       /in/GMJXg
function name:  page_walk
number of ops:  27
compiled vars:  !0 = $array, !1 = $parent_id, !2 = $organized_pages, !3 = $children, !4 = $page, !5 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      <false>
    4     2        ASSIGN                                                   !2, <array>
    6     3        ASSIGN                                                   !3, <array>
    8     4      > FE_RESET_R                                       $8      !0, ->24
          5    > > FE_FETCH_R                                       ~9      $8, !4, ->24
          6    >   ASSIGN                                                   !5, ~9
   10     7        FETCH_DIM_R                                      ~11     !4, 'parent_id'
          8        IS_EQUAL                                                 ~11, 0
          9      > JMPZ                                                     ~12, ->13
   12    10    >   ASSIGN_DIM                                               !2, !5
         11        OP_DATA                                                  !4
         12      > JMP                                                      ->23
   16    13    >   FETCH_DIM_R                                      ~16     !4, 'id'
         14        FETCH_THIS                                       $18     
         15        INIT_METHOD_CALL                                         $18, 'page_walk'
         16        SEND_VAR_EX                                              !4
         17        SEND_VAR_EX                                              !1
         18        DO_FCALL                                      0  $19     
         19        FETCH_DIM_W                                      $14     !2, !1
         20        FETCH_DIM_W                                      $15     $14, 'children'
         21        ASSIGN_DIM                                               $15, ~16
         22        OP_DATA                                                  $19
    8    23    > > JMP                                                      ->5
         24    >   FE_FREE                                                  $8
   20    25      > RETURN                                                   !2
   21    26*     > RETURN                                                   null

End of function page_walk

Function page_list:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GMJXg
function name:  page_list
number of ops:  20
compiled vars:  !0 = $array, !1 = $fakepages, !2 = $pages
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   RECV                                             !0      
   25     1        ASSIGN                                                   !1, <array>
   26     2        ASSIGN_DIM                                               !1, 0
          3        OP_DATA                                                  <array>
   27     4        ASSIGN_DIM                                               !1, 1
          5        OP_DATA                                                  <array>
   28     6        ASSIGN_DIM                                               !1, 2
          7        OP_DATA                                                  <array>
   29     8        ASSIGN_DIM                                               !1, 3
          9        OP_DATA                                                  <array>
   31    10        FETCH_THIS                                       $8      
         11        INIT_METHOD_CALL                                         $8, 'page_walk'
         12        SEND_VAR_EX                                              !1
         13        SEND_VAL_EX                                              0
         14        DO_FCALL                                      0  $9      
         15        ASSIGN                                                   !2, $9
   33    16        INIT_FCALL                                               'print_r'
         17        SEND_VAR                                                 !2
         18        DO_ICALL                                                 
   34    19      > RETURN                                                   null

End of function page_list

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.44 ms | 1405 KiB | 15 Q