3v4l.org

run code in 500+ 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 uasort($menu, function($a,$b) { return $a[1] == $b[1] ? ($a[4] < $b[4] ? -1 : 1) : ($a[1] < $b[1] ? -1 : 1); }); $cache = array(); foreach ($menu as $m) { if (!isset($cache[$m[1]])) { $cache[$m[1]] = array(); } $cache[$m[1]][] = $m; } function m($m, $l, $r) { foreach($m[$l] as $e) { $r[] = $e; if (isset($m[$e[0]])) { $r = m($m, $e[0], $r); } } return $r; } $result = m($cache, 0, array()); $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
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 21
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 21
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 16
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 16
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/nvuRW
function name:  (null)
number of ops:  34
compiled vars:  !0 = $menu, !1 = $cache, !2 = $m, !3 = $result, !4 = $target
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   17     1        INIT_FCALL                                                   'uasort'
          2        SEND_REF                                                     !0
          3        DECLARE_LAMBDA_FUNCTION                              ~6      [0]
   21     4        SEND_VAL                                                     ~6
   17     5        DO_ICALL                                                     
   23     6        ASSIGN                                                       !1, <array>
   25     7      > FE_RESET_R                                           $9      !0, ->21
          8    > > FE_FETCH_R                                                   $9, !2, ->21
   26     9    >   FETCH_DIM_R                                          ~10     !2, 1
         10        ISSET_ISEMPTY_DIM_OBJ                             0  ~11     !1, ~10
         11        BOOL_NOT                                             ~12     ~11
         12      > JMPZ                                                         ~12, ->16
   27    13    >   FETCH_DIM_R                                          ~13     !2, 1
         14        ASSIGN_DIM                                                   !1, ~13
         15        OP_DATA                                                      <array>
   29    16    >   FETCH_DIM_R                                          ~15     !2, 1
         17        FETCH_DIM_W                                          $16     !1, ~15
         18        ASSIGN_DIM                                                   $16
         19        OP_DATA                                                      !2
   25    20      > JMP                                                          ->8
         21    >   FE_FREE                                                      $9
   44    22        INIT_FCALL                                                   'm'
         23        SEND_VAR                                                     !1
         24        SEND_VAL                                                     0
         25        SEND_VAL                                                     <array>
         26        DO_FCALL                                          0  $18     
         27        ASSIGN                                                       !3, $18
   46    28        ASSIGN                                                       !4, <array>
   58    29        INIT_FCALL                                                   'var_dump'
         30        IS_EQUAL                                             ~21     !3, !4
         31        SEND_VAL                                                     ~21
         32        DO_ICALL                                                     
         33      > RETURN                                                       1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 12
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/nvuRW
function name:  {closure:/in/nvuRW:17}
number of ops:  25
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   17     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   18     2        FETCH_DIM_R                                          ~2      !0, 1
          3        FETCH_DIM_R                                          ~3      !1, 1
          4        IS_EQUAL                                                     ~2, ~3
          5      > JMPZ                                                         ~4, ->15
   19     6    >   FETCH_DIM_R                                          ~5      !0, 4
          7        FETCH_DIM_R                                          ~6      !1, 4
          8        IS_SMALLER                                                   ~5, ~6
          9      > JMPZ                                                         ~7, ->12
         10    >   QM_ASSIGN                                            ~8      -1
         11      > JMP                                                          ->13
         12    >   QM_ASSIGN                                            ~8      1
         13    >   QM_ASSIGN                                            ~9      ~8
         14      > JMP                                                          ->23
   20    15    >   FETCH_DIM_R                                          ~10     !0, 1
         16        FETCH_DIM_R                                          ~11     !1, 1
         17        IS_SMALLER                                                   ~10, ~11
         18      > JMPZ                                                         ~12, ->21
         19    >   QM_ASSIGN                                            ~13     -1
         20      > JMP                                                          ->22
         21    >   QM_ASSIGN                                            ~13     1
         22    >   QM_ASSIGN                                            ~9      ~13
         23    > > RETURN                                                       ~9
   21    24*     > RETURN                                                       null

End of Dynamic Function 0

Function m:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 19
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/nvuRW
function name:  m
number of ops:  23
compiled vars:  !0 = $m, !1 = $l, !2 = $r, !3 = $e
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   34     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   35     3        FETCH_DIM_R                                          ~4      !0, !1
          4      > FE_RESET_R                                           $5      ~4, ->20
          5    > > FE_FETCH_R                                                   $5, !3, ->20
   36     6    >   ASSIGN_DIM                                                   !2
          7        OP_DATA                                                      !3
   37     8        FETCH_DIM_R                                          ~7      !3, 0
          9        ISSET_ISEMPTY_DIM_OBJ                             0          !0, ~7
         10      > JMPZ                                                         ~8, ->19
   38    11    >   INIT_FCALL_BY_NAME                                           'm'
         12        SEND_VAR_EX                                                  !0
         13        CHECK_FUNC_ARG                                               
         14        FETCH_DIM_FUNC_ARG                                   $9      !3, 0
         15        SEND_FUNC_ARG                                                $9
         16        SEND_VAR_EX                                                  !2
         17        DO_FCALL                                          0  $10     
         18        ASSIGN                                                       !2, $10
   35    19    > > JMP                                                          ->5
         20    >   FE_FREE                                                      $5
   41    21      > RETURN                                                       !2
   42    22*     > RETURN                                                       null

End of function m

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.53 ms | 3208 KiB | 16 Q