3v4l.org

run code in 300+ PHP versions simultaneously
<?php $items = [ ['type' => 1, 'text' => 'A'], ['type' => 2, 'text' => 'B'], ['type' => 2, 'text' => 'C'], ['type' => 3, 'text' => 'D'], ['type' => 2, 'text' => 'E'], ['type' => 1, 'text' => 'F'], ['type' => 4, 'text' => 'G'], ['type' => 2, 'text' => 'H'], ['type' => 1, 'text' => 'I'], ['type' => 4, 'text' => 'J'], ['type' => 2, 'text' => 'K'], ['type' => 4, 'text' => 'L'], ['type' => 2, 'text' => 'M'], ['type' => 3, 'text' => 'N'], ['type' => 3, 'text' => 'O'], ['type' => 1, 'text' => 'P'], ['type' => 1, 'text' => 'Q'], ['type' => 2, 'text' => 'R'], ['type' => 3, 'text' => 'S'], ['type' => 2, 'text' => 'T'], ['type' => 3, 'text' => 'U'], ['type' => 2, 'text' => 'V'], ['type' => 3, 'text' => 'W'], ['type' => 2, 'text' => 'X'], ['type' => 4, 'text' => 'Y'], ['type' => 2, 'text' => 'Z'], ]; $maxConsecutive = 3; array_multisort( array_map( function ($row) use ($maxConsecutive) { static $encountered; $encountered[$row['type']] ??= 0; return intdiv($encountered[$row['type']]++, $maxConsecutive); }, $items ), array_column($items, 'type'), $items ); var_export($items);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cOSO1
function name:  (null)
number of ops:  21
compiled vars:  !0 = $items, !1 = $maxConsecutive
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   32     1        ASSIGN                                                   !1, 3
   34     2        INIT_FCALL                                               'array_multisort'
   35     3        INIT_FCALL                                               'array_map'
   36     4        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          5        BIND_LEXICAL                                             ~4, !1
   40     6        SEND_VAL                                                 ~4
   41     7        SEND_VAR                                                 !0
   35     8        DO_ICALL                                         $5      
   41     9        SEND_VAL                                                 $5
   43    10        INIT_FCALL                                               'array_column'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 'type'
         13        DO_ICALL                                         $6      
         14        SEND_VAL                                                 $6
   44    15        SEND_REF                                                 !0
   34    16        DO_ICALL                                                 
   47    17        INIT_FCALL                                               'var_export'
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                                 
         20      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cOSO1
function name:  {closure}
number of ops:  22
compiled vars:  !0 = $row, !1 = $maxConsecutive, !2 = $encountered
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   36     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   37     2        BIND_STATIC                                              !2
   38     3        FETCH_DIM_R                                      ~3      !0, 'type'
          4        COPY_TMP                                         ~4      ~3
          5        FETCH_DIM_IS                                     ~5      !2, ~3
          6        COALESCE                                         ~6      ~5
          7        ASSIGN_DIM                                       ~7      !2, ~4
          8        OP_DATA                                                  0
          9        QM_ASSIGN                                        ~6      ~7
         10      > JMP                                                      ->12
         11*       FREE                                                     ~4
         12    >   FREE                                                     ~6
   39    13        INIT_FCALL                                               'intdiv'
         14        FETCH_DIM_R                                      ~8      !0, 'type'
         15        FETCH_DIM_RW                                     $9      !2, ~8
         16        POST_INC                                         ~10     $9
         17        SEND_VAL                                                 ~10
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $11     
         20      > RETURN                                                   $11
   40    21*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.37 ms | 1007 KiB | 18 Q