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(); var_dump($result == $target); */ $items = array( array( 'mid' => 1, // Menuid 'pid' => 3, // parentid 'title' => 'Wurm 1.1', // title 'level' => 2, // level 'sid' => 10 // sortid ), array( 'mid' => 2, // Menuid 'pid' => 6, // parentid 'title' => 'Vogel 2.1', // title 'level' => 2, // level 'sid' => 30 // sortid ), array( 'mid' => 3, // Menuid 'pid' => 0, // parentid 'title' => 'Tiger 1', // title 'level' => 1, // level 'sid' => 10 // sortid ), array( 'mid' => 4, // Menuid 'pid' => 6, // parentid 'title' => 'Hund 2.2', // title 'level' => 2, // level 'sid' => 40 // sortid ), array( 'mid' => 5, // Menuid 'pid' => 3, // parentid 'title' => 'Katze 1.2', // title 'level' => 2, // level 'sid' => 11 // sortid ), array( 'mid' => 6, // Menuid 'pid' => 0, // parentid 'title' => 'Pferd 2', // title 'level' => 1, // level 'sid' => 20 // sortid ), array( 'mid' => 7, // Menuid 'pid' => 1, // parentid 'title' => 'Baer 1.1.1', // title 'level' => 3, // level 'sid' => 0 // sortid ), array( 'mid' => 8, // Menuid 'pid' => 3, // parentid 'title' => 'Schwein 1.3', // title 'level' => 2, // level 'sid' => 12 // sortid ), array( 'mid' => 9, // Menuid 'pid' => 4, // parentid 'title' => 'Esel 2.2.1', // title 'level' => 3, // level 'sid' => 0 // sortid ) ); function listItems($arr=array(), $pid=0, $level=1) { $result=''; foreach ($arr as $key => $item) { if (!in_array($pid, $item)) continue; if (($item['pid'] == $pid) && ($item['level'] == $level)) { $result .= $item['title'] . '>>' . listItems($arr, $item['mid'], ($level+1)); } } return $result; } listItems($items); /* foreach($items as $item){ } 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/B9FsQ
function name:  (null)
number of ops:  5
compiled vars:  !0 = $items
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   ASSIGN                                                   !0, <array>
  103     1        INIT_FCALL                                               'listitems'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
  157     4      > RETURN                                                   1

Function listitems:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 34
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 34
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 14
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 14
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 20
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 33
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 33
Branch analysis from position: 20
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
filename:       /in/B9FsQ
function name:  listItems
number of ops:  37
compiled vars:  !0 = $arr, !1 = $pid, !2 = $level, !3 = $result, !4 = $item, !5 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   87     0  E >   RECV_INIT                                        !0      <array>
          1        RECV_INIT                                        !1      0
          2        RECV_INIT                                        !2      1
   88     3        ASSIGN                                                   !3, ''
   90     4      > FE_RESET_R                                       $7      !0, ->34
          5    > > FE_FETCH_R                                       ~8      $7, !4, ->34
          6    >   ASSIGN                                                   !5, ~8
   91     7        INIT_FCALL                                               'in_array'
          8        SEND_VAR                                                 !1
          9        SEND_VAR                                                 !4
         10        DO_ICALL                                         $10     
         11        BOOL_NOT                                         ~11     $10
         12      > JMPZ                                                     ~11, ->14
         13    > > JMP                                                      ->5
   93    14    >   FETCH_DIM_R                                      ~12     !4, 'pid'
         15        IS_EQUAL                                         ~13     !1, ~12
         16      > JMPZ_EX                                          ~13     ~13, ->20
   94    17    >   FETCH_DIM_R                                      ~14     !4, 'level'
         18        IS_EQUAL                                         ~15     !2, ~14
         19        BOOL                                             ~13     ~15
         20    > > JMPZ                                                     ~13, ->33
   96    21    >   FETCH_DIM_R                                      ~16     !4, 'title'
         22        CONCAT                                           ~17     ~16, '%3E%3E'
         23        INIT_FCALL_BY_NAME                                       'listItems'
         24        SEND_VAR_EX                                              !0
         25        CHECK_FUNC_ARG                                           
         26        FETCH_DIM_FUNC_ARG                               $18     !4, 'mid'
         27        SEND_FUNC_ARG                                            $18
         28        ADD                                              ~19     !2, 1
         29        SEND_VAL_EX                                              ~19
         30        DO_FCALL                                      0  $20     
         31        CONCAT                                           ~21     ~17, $20
         32        ASSIGN_OP                                     8          !3, ~21
   90    33    > > JMP                                                      ->5
         34    >   FE_FREE                                                  $7
  100    35      > RETURN                                                   !3
  101    36*     > RETURN                                                   null

End of function listitems

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.67 ms | 1403 KiB | 16 Q