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(); function array_orderby() { $args = func_get_args(); $data = array_shift($args); foreach ($args as $n => $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 byTopId($items,$id) { $return = array(); foreach($items as $item) { if($item[1] == $id) { $return[] = $item; } } if(count($return) > 0) { $return = array_orderby($return,4); } return $return; } function sortMenu($menu,$topid,&$return) { $items = byTopId($menu,$topid); foreach($items as $item) { $return[] = $item; sortMenu($menu,$item[0],$return); } } $result = array(); sortMenu($menu,0,$result); $target = array( array(3,0,'Tiger 1', 1, 10), array(1,3,'Wurm 1.1', 2, 10), array(7,1,'Baer 1.1.1', 3, 0), array(5,3,'Katze 1.2', 2, 11), array(8,3,'Schwein 1.3', 2, 12), array(6,0,'Pferd 2', 1, 20), array(2,6,'Vogel 2.1', 2, 30), array(4,6,'Hund 2.2', 2, 40), array(9,4,'Esel 2.2.1', 3, 0), ); var_dump($result == $target);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5ANUC
function name:  (null)
number of ops:  14
compiled vars:  !0 = $menu, !1 = $result, !2 = $target
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   17     1        ASSIGN                                                   !1, <array>
   51     2        ASSIGN                                                   !1, <array>
   52     3        INIT_FCALL                                               'sortmenu'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 0
          6        SEND_REF                                                 !1
          7        DO_FCALL                                      0          
   54     8        ASSIGN                                                   !2, <array>
   66     9        INIT_FCALL                                               'var_dump'
         10        IS_EQUAL                                         ~8      !1, !2
         11        SEND_VAL                                                 ~8
         12        DO_ICALL                                                 
         13      > RETURN                                                   1

Function array_orderby:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 21
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 21
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 11, Position 2 = 17
Branch analysis from position: 11
2 jumps found. (Code = 78) Position 1 = 12, Position 2 = 17
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 17
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/5ANUC
function name:  array_orderby
number of ops:  33
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
-------------------------------------------------------------------------------------
   19     0  E >   FUNC_GET_ARGS                                    ~7      
          1        ASSIGN                                                   !0, ~7
   20     2        INIT_FCALL                                               'array_shift'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                         $9      
          5        ASSIGN                                                   !1, $9
   21     6      > FE_RESET_R                                       $11     !0, ->21
          7    > > FE_FETCH_R                                       ~12     $11, !2, ->21
          8    >   ASSIGN                                                   !3, ~12
   22     9        ASSIGN                                                   !4, <array>
   23    10      > FE_RESET_R                                       $15     !1, ->17
         11    > > FE_FETCH_R                                       ~16     $15, !5, ->17
         12    >   ASSIGN                                                   !6, ~16
   24    13        FETCH_DIM_R                                      ~19     !5, !2
         14        ASSIGN_DIM                                               !4, !6
         15        OP_DATA                                                  ~19
   23    16      > JMP                                                      ->11
         17    >   FE_FREE                                                  $15
   25    18        ASSIGN_DIM                                               !0, !3
         19        OP_DATA                                                  !4
   21    20      > JMP                                                      ->7
         21    >   FE_FREE                                                  $11
   27    22        FETCH_DIM_W                                      $21     !0
         23        ASSIGN_REF                                               $21, !1
   28    24        INIT_FCALL                                               'array_multisort'
         25        SEND_ARRAY                                               !0
         26        CHECK_UNDEF_ARGS                                         
         27        DO_FCALL                                      0          
   29    28        INIT_FCALL                                               'array_pop'
         29        SEND_REF                                                 !0
         30        DO_ICALL                                         $24     
         31      > RETURN                                                   $24
   30    32*     > RETURN                                                   null

End of function array_orderby

Function bytopid:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 10
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 10
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 20
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
Branch analysis from position: 11
filename:       /in/5ANUC
function name:  byTopId
number of ops:  22
compiled vars:  !0 = $items, !1 = $id, !2 = $return, !3 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   32     2        ASSIGN                                                   !2, <array>
   33     3      > FE_RESET_R                                       $5      !0, ->11
          4    > > FE_FETCH_R                                               $5, !3, ->11
   34     5    >   FETCH_DIM_R                                      ~6      !3, 1
          6        IS_EQUAL                                                 !1, ~6
          7      > JMPZ                                                     ~7, ->10
   35     8    >   ASSIGN_DIM                                               !2
          9        OP_DATA                                                  !3
   33    10    > > JMP                                                      ->4
         11    >   FE_FREE                                                  $5
   38    12        COUNT                                            ~9      !2
         13        IS_SMALLER                                               0, ~9
         14      > JMPZ                                                     ~10, ->20
   39    15    >   INIT_FCALL                                               'array_orderby'
         16        SEND_VAR                                                 !2
         17        SEND_VAL                                                 4
         18        DO_FCALL                                      0  $11     
         19        ASSIGN                                                   !2, $11
   41    20    > > RETURN                                                   !2
   42    21*     > RETURN                                                   null

End of function bytopid

Function sortmenu:
Finding entry points
Branch analysis from position: 0
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 = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/5ANUC
function name:  sortMenu
number of ops:  22
compiled vars:  !0 = $menu, !1 = $topid, !2 = $return, !3 = $items, !4 = $item
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   44     3        INIT_FCALL                                               'bytopid'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $5      
          7        ASSIGN                                                   !3, $5
   45     8      > FE_RESET_R                                       $7      !3, ->20
          9    > > FE_FETCH_R                                               $7, !4, ->20
   46    10    >   ASSIGN_DIM                                               !2
         11        OP_DATA                                                  !4
   47    12        INIT_FCALL_BY_NAME                                       'sortMenu'
         13        SEND_VAR_EX                                              !0
         14        CHECK_FUNC_ARG                                           
         15        FETCH_DIM_FUNC_ARG                               $9      !4, 0
         16        SEND_FUNC_ARG                                            $9
         17        SEND_VAR_EX                                              !2
         18        DO_FCALL                                      0          
   45    19      > JMP                                                      ->9
         20    >   FE_FREE                                                  $7
   49    21      > RETURN                                                   null

End of function sortmenu

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
183.32 ms | 1407 KiB | 24 Q