3v4l.org

run code in 300+ PHP versions simultaneously
<?php $menu = array( array(1,3,'Wurm 1.1', 2, 10), array(2,6,'Vogel 2.1', 2, 30), array(3,0,'Tiger 1', 1, 10), array(4,6,'Hund 2.2', 2, 40), array(5,3,'Katze 1.2', 2, 11), array(6,0,'Pferd 2', 1, 20), array(7,1,'Baer 1.1.1', 3, 0), array(8,3,'Schwein 1.3', 2, 12), array(9,4,'Esel 2.2.1', 3, 0), ); // Algorithmus hier $result = array(); $target = array( array(9,4,'Esel 2.2.1', 3, 0), ); var_dump($result == $target); $navitems = array( array( 1, // Menuid 3, // parentid 'Wurm 1.1', // title 2, // level 10 // sortid ), array( 2, // Menuid 6, // parentid 'Vogel 2.1', // title 2, // level 30 // sortid ), array( 3, // Menuid 0, // parentid 'Tiger 1', // title 1, // level 10 // sortid ), array( 4, // Menuid 6, // parentid 'Hund 2.2', // title 2, // level 40 // sortid ), array( 5, // Menuid 3, // parentid 'Katze 1.2', // title 2, // level 11 // sortid ), array( 6, // Menuid 0, // parentid 'Pferd 2', // title 1, // level 20 // sortid ), array( 7, // Menuid 1, // parentid 'Baer 1.1.1', // title 3, // level 0 // sortid ), array( 8, // Menuid 3, // parentid 'Schwein 1.3', // title 2, // level 12 // sortid ), array( 9, // Menuid 4, // parentid 'Esel 2.2.1', // title 3, // level 0 // sortid ) ); function array_orderby() { $args = func_get_args(); $data = array_shift($args); foreach ($args as $n => $field) { if (is_string($field)) { $tmp = array(); foreach ($data as $key => $row) $tmp[$key] = $row[$field]; $args[$n] = $tmp; } } $args[] = &$data; call_user_func_array('array_multisort', $args); return array_pop($args); } function listItems($items, $level=0, $child=false, $pid=0) { array_orderby($items, 'sortid'); $rest = ''; foreach($items as $item) { if ($item[3] != $level) { continue; } if ($child == false) { $rest .= '<li>'. $item[2] .'<ul>'. listItems($items, $level+1, true, $item[0]) .'</ul></li>'; } else { if ($pid == $item[1]) { $rest .= '<li>'. $item[2] .'<ul>'. listItems($items, $level+1, true, $item[0]) .'</ul></li>'; } } } return '<ul>' . $rest . '</ul>'; } echo listItems();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eHESA
function name:  (null)
number of ops:  12
compiled vars:  !0 = $menu, !1 = $result, !2 = $target, !3 = $navitems
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   17     1        ASSIGN                                                   !1, <array>
   21     2        ASSIGN                                                   !2, <array>
   25     3        INIT_FCALL                                               'var_dump'
          4        IS_EQUAL                                         ~7      !1, !2
          5        SEND_VAL                                                 ~7
          6        DO_ICALL                                                 
   27     7        ASSIGN                                                   !3, <array>
  136     8        INIT_FCALL                                               'listitems'
          9        DO_FCALL                                      0  $10     
         10        ECHO                                                     $10
         11      > RETURN                                                   1

Function array_orderby:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 23
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 23
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 19
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 19
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 19
Branch analysis from position: 22
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/eHESA
function name:  array_orderby
number of ops:  35
compiled vars:  !0 = $args, !1 = $data, !2 = $field, !3 = $n, !4 = $tmp, !5 = $row, !6 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   95     0  E >   FUNC_GET_ARGS                                    ~7      
          1        ASSIGN                                                   !0, ~7
   96     2        INIT_FCALL                                               'array_shift'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                         $9      
          5        ASSIGN                                                   !1, $9
   98     6      > FE_RESET_R                                       $11     !0, ->23
          7    > > FE_FETCH_R                                       ~12     $11, !2, ->23
          8    >   ASSIGN                                                   !3, ~12
   99     9        TYPE_CHECK                                   64          !2
         10      > JMPZ                                                     ~14, ->22
  100    11    >   ASSIGN                                                   !4, <array>
  101    12      > FE_RESET_R                                       $16     !1, ->19
         13    > > FE_FETCH_R                                       ~17     $16, !5, ->19
         14    >   ASSIGN                                                   !6, ~17
  102    15        FETCH_DIM_R                                      ~20     !5, !2
         16        ASSIGN_DIM                                               !4, !6
         17        OP_DATA                                                  ~20
  101    18      > JMP                                                      ->13
         19    >   FE_FREE                                                  $16
  103    20        ASSIGN_DIM                                               !0, !3
         21        OP_DATA                                                  !4
   98    22    > > JMP                                                      ->7
         23    >   FE_FREE                                                  $11
  107    24        FETCH_DIM_W                                      $22     !0
         25        ASSIGN_REF                                               $22, !1
  109    26        INIT_FCALL                                               'array_multisort'
         27        SEND_ARRAY                                               !0
         28        CHECK_UNDEF_ARGS                                         
         29        DO_FCALL                                      0          
  110    30        INIT_FCALL                                               'array_pop'
         31        SEND_REF                                                 !0
         32        DO_ICALL                                         $25     
         33      > RETURN                                                   $25
  111    34*     > RETURN                                                   null

End of function array_orderby

Function listitems:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 52
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 52
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 15
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 33
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 36, Position 2 = 51
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 51
Branch analysis from position: 52
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 52
filename:       /in/eHESA
function name:  listItems
number of ops:  57
compiled vars:  !0 = $items, !1 = $level, !2 = $child, !3 = $pid, !4 = $rest, !5 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  114     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      <false>
          3        RECV_INIT                                        !3      0
  115     4        INIT_FCALL                                               'array_orderby'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 'sortid'
          7        DO_FCALL                                      0          
  117     8        ASSIGN                                                   !4, ''
  119     9      > FE_RESET_R                                       $8      !0, ->52
         10    > > FE_FETCH_R                                               $8, !5, ->52
  120    11    >   FETCH_DIM_R                                      ~9      !5, 3
         12        IS_NOT_EQUAL                                             !1, ~9
         13      > JMPZ                                                     ~10, ->15
  121    14    > > JMP                                                      ->10
  124    15    >   BOOL_NOT                                         ~11     !2
         16      > JMPZ                                                     ~11, ->33
  125    17    >   FETCH_DIM_R                                      ~12     !5, 2
         18        CONCAT                                           ~13     '%3Cli%3E', ~12
         19        CONCAT                                           ~14     ~13, '%3Cul%3E'
         20        INIT_FCALL_BY_NAME                                       'listItems'
         21        SEND_VAR_EX                                              !0
         22        ADD                                              ~15     !1, 1
         23        SEND_VAL_EX                                              ~15
         24        SEND_VAL_EX                                              <true>
         25        CHECK_FUNC_ARG                                           
         26        FETCH_DIM_FUNC_ARG                               $16     !5, 0
         27        SEND_FUNC_ARG                                            $16
         28        DO_FCALL                                      0  $17     
         29        CONCAT                                           ~18     ~14, $17
         30        CONCAT                                           ~19     ~18, '%3C%2Ful%3E%3C%2Fli%3E'
         31        ASSIGN_OP                                     8          !4, ~19
         32      > JMP                                                      ->51
  127    33    >   FETCH_DIM_R                                      ~21     !5, 1
         34        IS_EQUAL                                                 !3, ~21
         35      > JMPZ                                                     ~22, ->51
  128    36    >   FETCH_DIM_R                                      ~23     !5, 2
         37        CONCAT                                           ~24     '%3Cli%3E', ~23
         38        CONCAT                                           ~25     ~24, '%3Cul%3E'
         39        INIT_FCALL_BY_NAME                                       'listItems'
         40        SEND_VAR_EX                                              !0
         41        ADD                                              ~26     !1, 1
         42        SEND_VAL_EX                                              ~26
         43        SEND_VAL_EX                                              <true>
         44        CHECK_FUNC_ARG                                           
         45        FETCH_DIM_FUNC_ARG                               $27     !5, 0
         46        SEND_FUNC_ARG                                            $27
         47        DO_FCALL                                      0  $28     
         48        CONCAT                                           ~29     ~25, $28
         49        CONCAT                                           ~30     ~29, '%3C%2Ful%3E%3C%2Fli%3E'
         50        ASSIGN_OP                                     8          !4, ~30
  119    51    > > JMP                                                      ->10
         52    >   FE_FREE                                                  $8
  133    53        CONCAT                                           ~32     '%3Cul%3E', !4
         54        CONCAT                                           ~33     ~32, '%3C%2Ful%3E'
         55      > RETURN                                                   ~33
  134    56*     > RETURN                                                   null

End of function listitems

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.96 ms | 1407 KiB | 23 Q