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 usort($menu, function($a,$b) { return $a[3] == $b[3] ? ($a[4] < $b[4] ? -1 : 1) : ($a[3] < $b[3] ? -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; } */ var_dump($menu); $result = $menu; $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/k27ZR
function name:  (null)
number of ops:  17
compiled vars:  !0 = $menu, !1 = $cache, !2 = $result, !3 = $target
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   17     1        INIT_FCALL                                               'usort'
          2        SEND_REF                                                 !0
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Fk27ZR%3A17%240'
   21     4        SEND_VAL                                                 ~5
          5        DO_ICALL                                                 
   23     6        ASSIGN                                                   !1, <array>
   46     7        INIT_FCALL                                               'var_dump'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                                 
   48    10        ASSIGN                                                   !2, !0
   50    11        ASSIGN                                                   !3, <array>
   62    12        INIT_FCALL                                               'var_dump'
         13        IS_EQUAL                                         ~11     !2, !3
         14        SEND_VAL                                                 ~11
         15        DO_ICALL                                                 
         16      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Fk27ZR%3A17%240:
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/k27ZR
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, 3
          3        FETCH_DIM_R                                      ~3      !1, 3
          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, 3
         16        FETCH_DIM_R                                      ~11     !1, 3
         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 function %00%7Bclosure%7D%2Fin%2Fk27ZR%3A17%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.2 ms | 1400 KiB | 17 Q