3v4l.org

run code in 500+ PHP versions simultaneously
<?php $input = [1, 2, 3, 5, 4, 7, 6, 8, 9]; $batches = generateBatches($input); function generateBatches($input) { $batches = []; $batchNumber = 0; $prev = 0; foreach ($input as $i) { $batches[$batchNumber][] = $i; if ($i > 1 && $i - $prev < 1) { $batchNumber++; } $prev = $i; } return $batches; } print_r($batches);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/n1kYl
function name:  (null)
number of ops:  9
compiled vars:  !0 = $input, !1 = $batches
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    5     1        INIT_FCALL_BY_NAME                                           'generateBatches'
          2        SEND_VAR_EX                                                  !0
          3        DO_FCALL                                          0  $3      
          4        ASSIGN                                                       !1, $3
   27     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 = 77) Position 1 = 5, Position 2 = 18
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 16
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 16
Branch analysis from position: 14
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/n1kYl
function name:  generateBatches
number of ops:  21
compiled vars:  !0 = $input, !1 = $batches, !2 = $batchNumber, !3 = $prev, !4 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    7     0  E >   RECV                                                 !0      
    9     1        ASSIGN                                                       !1, <array>
   10     2        ASSIGN                                                       !2, 0
   11     3        ASSIGN                                                       !3, 0
   13     4      > FE_RESET_R                                           $8      !0, ->18
          5    > > FE_FETCH_R                                                   $8, !4, ->18
   15     6    >   FETCH_DIM_W                                          $9      !1, !2
          7        ASSIGN_DIM                                                   $9
          8        OP_DATA                                                      !4
   17     9        IS_SMALLER                                           ~11     1, !4
         10      > JMPZ_EX                                              ~11     ~11, ->14
         11    >   SUB                                                  ~12     !4, !3
         12        IS_SMALLER                                           ~13     ~12, 1
         13        BOOL                                                 ~11     ~13
         14    > > JMPZ                                                         ~11, ->16
   18    15    >   PRE_INC                                                      !2
   21    16    >   ASSIGN                                                       !3, !4
   13    17      > JMP                                                          ->5
         18    >   FE_FREE                                                      $8
   24    19      > RETURN                                                       !1
   25    20*     > RETURN                                                       null

End of function generatebatches

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.71 ms | 2641 KiB | 14 Q