3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_split($input, $size=1) { $result = array(); for ($i = 0; $i < $size; $i++) { $remaining_slots = $size - $i; $remaining_items = count($input); $chunk_size = ceil($remaining_items / $remaining_slots); $chunk = array(); for ($e = 0; $e < $chunk_size; $e++) { $chunk[] = array_shift($input); } $result[] = $chunk; } return $result; } var_dump(array_split(range(0, 13), 3));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JnAsT
function name:  (null)
number of ops:  12
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_FCALL                                               'array_split'
          2        INIT_FCALL                                               'range'
          3        SEND_VAL                                                 0
          4        SEND_VAL                                                 13
          5        DO_ICALL                                         $0      
          6        SEND_VAR                                                 $0
          7        SEND_VAL                                                 3
          8        DO_FCALL                                      0  $1      
          9        SEND_VAR                                                 $1
         10        DO_ICALL                                                 
         11      > RETURN                                                   1

Function array_split:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 5
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 17
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 5
Branch analysis from position: 30
Branch analysis from position: 5
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 17
Branch analysis from position: 25
Branch analysis from position: 17
filename:       /in/JnAsT
function name:  array_split
number of ops:  32
compiled vars:  !0 = $input, !1 = $size, !2 = $result, !3 = $i, !4 = $remaining_slots, !5 = $remaining_items, !6 = $chunk_size, !7 = $chunk, !8 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      1
    4     2        ASSIGN                                                   !2, <array>
    6     3        ASSIGN                                                   !3, 0
          4      > JMP                                                      ->28
    7     5    >   SUB                                              ~11     !1, !3
          6        ASSIGN                                                   !4, ~11
    8     7        COUNT                                            ~13     !0
          8        ASSIGN                                                   !5, ~13
   10     9        INIT_FCALL                                               'ceil'
         10        DIV                                              ~15     !5, !4
         11        SEND_VAL                                                 ~15
         12        DO_ICALL                                         $16     
         13        ASSIGN                                                   !6, $16
   12    14        ASSIGN                                                   !7, <array>
   13    15        ASSIGN                                                   !8, 0
         16      > JMP                                                      ->23
   14    17    >   INIT_FCALL                                               'array_shift'
         18        SEND_REF                                                 !0
         19        DO_ICALL                                         $21     
         20        ASSIGN_DIM                                               !7
         21        OP_DATA                                                  $21
   13    22        PRE_INC                                                  !8
         23    >   IS_SMALLER                                               !8, !6
         24      > JMPNZ                                                    ~23, ->17
   16    25    >   ASSIGN_DIM                                               !2
         26        OP_DATA                                                  !7
    6    27        PRE_INC                                                  !3
         28    >   IS_SMALLER                                               !3, !1
         29      > JMPNZ                                                    ~26, ->5
   18    30    > > RETURN                                                   !2
   19    31*     > RETURN                                                   null

End of function array_split

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.49 ms | 1394 KiB | 22 Q