3v4l.org

run code in 300+ PHP versions simultaneously
<?php function partition($arr, ...$chunks) { $res = []; foreach($chunks as $n) { $res[] = array_splice($arr, 0, $n); } return $res; } $arr = ['a', 'f', 'j', 'r', 'c', 'j', 'd']; print_r(partition($arr, 2, 3, 2)); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/STiQ7
function name:  (null)
number of ops:  11
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ASSIGN                                                   !0, <array>
   12     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'partition'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 2
          5        SEND_VAL                                                 3
          6        SEND_VAL                                                 2
          7        DO_FCALL                                      0  $2      
          8        SEND_VAR                                                 $2
          9        DO_ICALL                                                 
   14    10      > RETURN                                                   1

Function partition:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/STiQ7
function name:  partition
number of ops:  16
compiled vars:  !0 = $arr, !1 = $chunks, !2 = $res, !3 = $n
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_VARIADIC                                    !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3      > FE_RESET_R                                       $5      !1, ->13
          4    > > FE_FETCH_R                                               $5, !3, ->13
    6     5    >   INIT_FCALL                                               'array_splice'
          6        SEND_REF                                                 !0
          7        SEND_VAL                                                 0
          8        SEND_VAR                                                 !3
          9        DO_ICALL                                         $7      
         10        ASSIGN_DIM                                               !2
         11        OP_DATA                                                  $7
    5    12      > JMP                                                      ->4
         13    >   FE_FREE                                                  $5
    8    14      > RETURN                                                   !2
    9    15*     > RETURN                                                   null

End of function partition

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
143.84 ms | 1002 KiB | 16 Q