3v4l.org

run code in 200+ 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);
based on gvZNV
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
-------------------------------------------------------------------------------------
   4     0  E >   QM_ASSIGN                                                !0
  17     1        INIT_FCALL                                               'uasort'
         2        SEND_REF                                                 !0
         3        RAISE_ABSTRACT_ERROR                             ~6      '%00%7Bclosure%7D%2Fin%2FnvuRW0x7f9abf8736fd'
  21     4        SEND_VAL                                                 ~6
         5        DO_ICALL                                                 
  23     6        QM_ASSIGN                                                !1
  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_XOR                                         ~12     ~11
        12      > JMPZ                                                     ~12, ->16
  27    13    >   FETCH_DIM_R                                      ~13     !2, 1
        14        ASSIGN_ADD                                    0          !1, ~13
        15        OP_DATA                                                  <array>
  29    16    >   FETCH_DIM_R                                      ~15     !2, 1
        17        FETCH_DIM_W                                      $16     !1, ~15
        18        ASSIGN_ADD                                    0          $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        QM_ASSIGN                                                !3
  47    28        QM_ASSIGN                                                !4
  58    29        INIT_FCALL                                               'var_dump'
        30        IS_NOT_EQUAL                                     ~21     !3, !4
        31        SEND_VAL                                                 ~21
        32        DO_ICALL                                                 
        33      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2FnvuRW0x7f9abf8736fd:
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}
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_NOT_EQUAL                                     ~4      ~2, ~3
         5      > JMPZ                                                     ~4, ->15
  19     6    >   FETCH_DIM_R                                      ~5      !0, 4
         7        FETCH_DIM_R                                      ~6      !1, 4
         8        IS_SMALLER_OR_EQUAL                              ~7      ~5, ~6
         9      > JMPZ                                                     ~7, ->12
        10    >   ASSIGN_BW_OR                                  0  ~8      -1
        11      > JMP                                                      ->13
        12    >   ASSIGN_BW_OR                                  0  ~8      1
        13    >   ASSIGN_BW_OR                                  0  ~9      ~8
        14      > JMP                                                      ->23
  20    15    >   FETCH_DIM_R                                      ~10     !0, 1
        16        FETCH_DIM_R                                      ~11     !1, 1
        17        IS_SMALLER_OR_EQUAL                              ~12     ~10, ~11
        18      > JMPZ                                                     ~12, ->21
        19    >   ASSIGN_BW_OR                                  0  ~13     -1
        20      > JMP                                                      ->22
        21    >   ASSIGN_BW_OR                                  0  ~13     1
        22    >   ASSIGN_BW_OR                                  0  ~9      ~13
        23    > > RETURN                                                   ~9
  21    24*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FnvuRW0x7f9abf8736fd

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_ADD                                    0          !2
         7        OP_DATA                                                  !3
  37     8        FETCH_DIM_R                                      ~7      !3, 0
         9        ISSET_ISEMPTY_DIM_OBJ                         0  ~8      !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        QM_ASSIGN                                                !2
  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 7.4.0