3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [1, 2, 3, 5, 4, 7, 6, 8, 9]; $batches = generateBatches($input); function generateBatches($input) { $length = count($input); if (0 === $length) { return []; } $batches = []; $prev = $input[0]; $currentBatch = [$prev]; for ($i = 1; $i < $length; $i++) { if ($i < $prev) { $batches[] = $currentBatch; $currentBatch = []; } $currentBatch[] = $prev = $input[$i]; } $batches[] = $currentBatch; return $batches; } print_r($batches);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mMmZa
function name:  (null)
number of ops:  9
compiled vars:  !0 = $input, !1 = $batches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL_BY_NAME                                       'generateBatches'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0  $3      
          4        ASSIGN                                                   !1, $3
   29     5        INIT_FCALL                                               'print_r'
          6        SEND_VAR                                                 !1
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function generatebatches:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 13
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 13
Branch analysis from position: 25
Branch analysis from position: 13
Branch analysis from position: 18
filename:       /in/mMmZa
function name:  generateBatches
number of ops:  29
compiled vars:  !0 = $input, !1 = $length, !2 = $batches, !3 = $prev, !4 = $currentBatch, !5 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        COUNT                                            ~6      !0
          2        ASSIGN                                                   !1, ~6
    8     3        IS_IDENTICAL                                             !1, 0
          4      > JMPZ                                                     ~8, ->6
    9     5    > > RETURN                                                   <array>
   12     6    >   ASSIGN                                                   !2, <array>
   13     7        FETCH_DIM_R                                      ~10     !0, 0
          8        ASSIGN                                                   !3, ~10
   14     9        INIT_ARRAY                                       ~12     !3
         10        ASSIGN                                                   !4, ~12
   15    11        ASSIGN                                                   !5, 1
         12      > JMP                                                      ->23
   16    13    >   IS_SMALLER                                               !5, !3
         14      > JMPZ                                                     ~15, ->18
   17    15    >   ASSIGN_DIM                                               !2
         16        OP_DATA                                                  !4
   18    17        ASSIGN                                                   !4, <array>
   21    18    >   FETCH_DIM_R                                      ~19     !0, !5
         19        ASSIGN                                           ~20     !3, ~19
         20        ASSIGN_DIM                                               !4
         21        OP_DATA                                                  ~20
   15    22        PRE_INC                                                  !5
         23    >   IS_SMALLER                                               !5, !1
         24      > JMPNZ                                                    ~22, ->13
   24    25    >   ASSIGN_DIM                                               !2
         26        OP_DATA                                                  !4
   26    27      > RETURN                                                   !2
   27    28*     > RETURN                                                   null

End of function generatebatches

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.19 ms | 1015 KiB | 14 Q