3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", ]; function chunkRange(array $arr, int ... $sizes): Generator { $t = 0; $s = count($arr); do { foreach ($sizes as $n => $size) { yield array_slice($arr, $t, $size); $t += $size; } } while($t < $s); } foreach (chunkRange($arr, 1, 2) as $group) { var_dump($group); }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 12
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/DEQ0D
function name:  (null)
number of ops:  14
compiled vars:  !0 = $arr, !1 = $group
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
   28     1        INIT_FCALL                                               'chunkrange'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 1
          4        SEND_VAL                                                 2
          5        DO_FCALL                                      0  $3      
          6      > FE_RESET_R                                       $4      $3, ->12
          7    > > FE_FETCH_R                                               $4, !1, ->12
   29     8    >   INIT_FCALL                                               'var_dump'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                                 
   28    11      > JMP                                                      ->7
         12    >   FE_FREE                                                  $4
   30    13      > RETURN                                                   1

Function chunkrange:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 17
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 17
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 6
Branch analysis from position: 20
1 jumps found. (Code = 161) Position 1 = -2
Branch analysis from position: 6
Branch analysis from position: 17
filename:       /in/DEQ0D
function name:  chunkRange
number of ops:  21
compiled vars:  !0 = $arr, !1 = $sizes, !2 = $t, !3 = $s, !4 = $size, !5 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        RECV_VARIADIC                                    !1      
          2        GENERATOR_CREATE                                         
   17     3        ASSIGN                                                   !2, 0
   18     4        COUNT                                            ~7      !0
          5        ASSIGN                                                   !3, ~7
   21     6    > > FE_RESET_R                                       $9      !1, ->17
          7    > > FE_FETCH_R                                       ~10     $9, !4, ->17
          8    >   ASSIGN                                                   !5, ~10
   22     9        INIT_FCALL                                               'array_slice'
         10        SEND_VAR                                                 !0
         11        SEND_VAR                                                 !2
         12        SEND_VAR                                                 !4
         13        DO_ICALL                                         $12     
         14        YIELD                                                    $12
   23    15        ASSIGN_OP                                     1          !2, !4
   21    16      > JMP                                                      ->7
         17    >   FE_FREE                                                  $9
   25    18        IS_SMALLER                                               !2, !3
         19      > JMPNZ                                                    ~15, ->6
   26    20    > > GENERATOR_RETURN                                         

End of function chunkrange

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.8 ms | 1010 KiB | 16 Q