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

End of function listitems

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.92 ms | 1407 KiB | 23 Q