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_msort($array, $cols) { $colarr = array(); foreach ($cols as $col => $order) { $colarr[$col] = array(); foreach ($array as $k => $row) { $colarr[$col]['_'.$k] = strtolower($row[$col]); } } $eval = 'array_multisort('; foreach ($cols as $col => $order) { $eval .= '$colarr[\''.$col.'\'],'.$order.','; } $eval = substr($eval,0,-1).');'; eval($eval); $ret = array(); foreach ($colarr as $col => $arr) { foreach ($arr as $k => $v) { $k = substr($k,1); if (!isset($ret[$k])) $ret[$k] = $array[$k]; $ret[$k][$col] = $array[$k][$col]; } } return $ret; } function listItems($items, $level=0, $child=false, $pid=0) { array_msort($items, array(4 => SORT_DESC)); $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($navitems);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/jrlJ1
function name:  (null)
number of ops:  13
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>
  140     8        INIT_FCALL                                               'listitems'
          9        SEND_VAR                                                 !3
         10        DO_FCALL                                      0  $10     
         11        ECHO                                                     $10
         12      > RETURN                                                   1

Function array_msort:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 22
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 22
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 20
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 20
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 20
Branch analysis from position: 22
2 jumps found. (Code = 77) Position 1 = 25, Position 2 = 33
Branch analysis from position: 25
2 jumps found. (Code = 78) Position 1 = 26, Position 2 = 33
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
Branch analysis from position: 33
2 jumps found. (Code = 77) Position 1 = 44, Position 2 = 68
Branch analysis from position: 44
2 jumps found. (Code = 78) Position 1 = 45, Position 2 = 68
Branch analysis from position: 45
2 jumps found. (Code = 77) Position 1 = 47, Position 2 = 66
Branch analysis from position: 47
2 jumps found. (Code = 78) Position 1 = 48, Position 2 = 66
Branch analysis from position: 48
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 60
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 60
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 44
Branch analysis from position: 44
Branch analysis from position: 66
Branch analysis from position: 68
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
Branch analysis from position: 33
Branch analysis from position: 22
filename:       /in/jrlJ1
function name:  array_msort
number of ops:  71
compiled vars:  !0 = $array, !1 = $cols, !2 = $colarr, !3 = $order, !4 = $col, !5 = $row, !6 = $k, !7 = $eval, !8 = $ret, !9 = $arr, !10 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   93     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   95     2        ASSIGN                                                   !2, <array>
   96     3      > FE_RESET_R                                       $12     !1, ->22
          4    > > FE_FETCH_R                                       ~13     $12, !3, ->22
          5    >   ASSIGN                                                   !4, ~13
   97     6        ASSIGN_DIM                                               !2, !4
          7        OP_DATA                                                  <array>
   98     8      > FE_RESET_R                                       $16     !0, ->20
          9    > > FE_FETCH_R                                       ~17     $16, !5, ->20
         10    >   ASSIGN                                                   !6, ~17
         11        CONCAT                                           ~20     '_', !6
         12        INIT_FCALL                                               'strtolower'
         13        FETCH_DIM_R                                      ~22     !5, !4
         14        SEND_VAL                                                 ~22
         15        DO_ICALL                                         $23     
         16        FETCH_DIM_W                                      $19     !2, !4
         17        ASSIGN_DIM                                               $19, ~20
         18        OP_DATA                                                  $23
         19      > JMP                                                      ->9
         20    >   FE_FREE                                                  $16
   96    21      > JMP                                                      ->4
         22    >   FE_FREE                                                  $12
  100    23        ASSIGN                                                   !7, 'array_multisort%28'
  101    24      > FE_RESET_R                                       $25     !1, ->33
         25    > > FE_FETCH_R                                       ~26     $25, !3, ->33
         26    >   ASSIGN                                                   !4, ~26
  102    27        CONCAT                                           ~28     '%24colarr%5B%27', !4
         28        CONCAT                                           ~29     ~28, '%27%5D%2C'
         29        CONCAT                                           ~30     ~29, !3
         30        CONCAT                                           ~31     ~30, '%2C'
         31        ASSIGN_OP                                     8          !7, ~31
  101    32      > JMP                                                      ->25
         33    >   FE_FREE                                                  $25
  104    34        INIT_FCALL                                               'substr'
         35        SEND_VAR                                                 !7
         36        SEND_VAL                                                 0
         37        SEND_VAL                                                 -1
         38        DO_ICALL                                         $33     
         39        CONCAT                                           ~34     $33, '%29%3B'
         40        ASSIGN                                                   !7, ~34
  105    41        INCLUDE_OR_EVAL                                          !7, EVAL
  106    42        ASSIGN                                                   !8, <array>
  107    43      > FE_RESET_R                                       $38     !2, ->68
         44    > > FE_FETCH_R                                       ~39     $38, !9, ->68
         45    >   ASSIGN                                                   !4, ~39
  108    46      > FE_RESET_R                                       $41     !9, ->66
         47    > > FE_FETCH_R                                       ~42     $41, !10, ->66
         48    >   ASSIGN                                                   !6, ~42
  109    49        INIT_FCALL                                               'substr'
         50        SEND_VAR                                                 !6
         51        SEND_VAL                                                 1
         52        DO_ICALL                                         $44     
         53        ASSIGN                                                   !6, $44
  110    54        ISSET_ISEMPTY_DIM_OBJ                         0  ~46     !8, !6
         55        BOOL_NOT                                         ~47     ~46
         56      > JMPZ                                                     ~47, ->60
         57    >   FETCH_DIM_R                                      ~49     !0, !6
         58        ASSIGN_DIM                                               !8, !6
         59        OP_DATA                                                  ~49
  111    60    >   FETCH_DIM_R                                      ~52     !0, !6
         61        FETCH_DIM_R                                      ~53     ~52, !4
         62        FETCH_DIM_W                                      $50     !8, !6
         63        ASSIGN_DIM                                               $50, !4
         64        OP_DATA                                                  ~53
  108    65      > JMP                                                      ->47
         66    >   FE_FREE                                                  $41
  107    67      > JMP                                                      ->44
         68    >   FE_FREE                                                  $38
  114    69      > RETURN                                                   !8
  116    70*     > RETURN                                                   null

End of function array_msort

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/jrlJ1
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
-------------------------------------------------------------------------------------
  118     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      <false>
          3        RECV_INIT                                        !3      0
  119     4        INIT_FCALL                                               'array_msort'
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 <array>
          7        DO_FCALL                                      0          
  121     8        ASSIGN                                                   !4, ''
  123     9      > FE_RESET_R                                       $8      !0, ->52
         10    > > FE_FETCH_R                                               $8, !5, ->52
  124    11    >   FETCH_DIM_R                                      ~9      !5, 3
         12        IS_NOT_EQUAL                                             !1, ~9
         13      > JMPZ                                                     ~10, ->15
  125    14    > > JMP                                                      ->10
  128    15    >   BOOL_NOT                                         ~11     !2
         16      > JMPZ                                                     ~11, ->33
  129    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
  131    33    >   FETCH_DIM_R                                      ~21     !5, 1
         34        IS_EQUAL                                                 !3, ~21
         35      > JMPZ                                                     ~22, ->51
  132    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
  123    51    > > JMP                                                      ->10
         52    >   FE_FREE                                                  $8
  137    53        CONCAT                                           ~32     '%3Cul%3E', !4
         54        CONCAT                                           ~33     ~32, '%3C%2Ful%3E'
         55      > RETURN                                                   ~33
  138    56*     > RETURN                                                   null

End of function listitems

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.37 ms | 1411 KiB | 21 Q