3v4l.org

run code in 300+ PHP versions simultaneously
<?php function custom_chunk($array, $maxrows) { $result = []; $size = sizeof($array); $columns = ceil($size / $maxrows); $fullrows = $size - ($columns - 1) * $maxrows; for ($i = 0; $i < $maxrows; ++$i) { $result[] = implode(', ', array_splice($array, 0, ($i < $fullrows ? $columns : $columns - 1))); } return $result; } $data = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5', 'Item 6', 'Item 7']; var_export(custom_chunk($data, 3));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/r9ZlN
function name:  (null)
number of ops:  9
compiled vars:  !0 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   ASSIGN                                                   !0, <array>
   16     1        INIT_FCALL                                               'var_export'
          2        INIT_FCALL                                               'custom_chunk'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 3
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function custom_chunk:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 16
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 25
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 16
Branch analysis from position: 36
Branch analysis from position: 16
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 16
Branch analysis from position: 36
Branch analysis from position: 16
filename:       /in/r9ZlN
function name:  custom_chunk
number of ops:  38
compiled vars:  !0 = $array, !1 = $maxrows, !2 = $result, !3 = $size, !4 = $columns, !5 = $fullrows, !6 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    3     2        ASSIGN                                                   !2, <array>
    4     3        COUNT                                            ~8      !0
          4        ASSIGN                                                   !3, ~8
    5     5        INIT_FCALL                                               'ceil'
          6        DIV                                              ~10     !3, !1
          7        SEND_VAL                                                 ~10
          8        DO_ICALL                                         $11     
          9        ASSIGN                                                   !4, $11
    6    10        SUB                                              ~13     !4, 1
         11        MUL                                              ~14     !1, ~13
         12        SUB                                              ~15     !3, ~14
         13        ASSIGN                                                   !5, ~15
    8    14        ASSIGN                                                   !6, 0
         15      > JMP                                                      ->34
    9    16    >   INIT_FCALL                                               'implode'
         17        SEND_VAL                                                 '%2C+'
         18        INIT_FCALL                                               'array_splice'
         19        SEND_REF                                                 !0
         20        SEND_VAL                                                 0
         21        IS_SMALLER                                               !6, !5
         22      > JMPZ                                                     ~19, ->25
         23    >   QM_ASSIGN                                        ~20     !4
         24      > JMP                                                      ->27
         25    >   SUB                                              ~21     !4, 1
         26        QM_ASSIGN                                        ~20     ~21
         27    >   SEND_VAL                                                 ~20
         28        DO_ICALL                                         $22     
         29        SEND_VAR                                                 $22
         30        DO_ICALL                                         $23     
         31        ASSIGN_DIM                                               !2
         32        OP_DATA                                                  $23
    8    33        PRE_INC                                                  !6
         34    >   IS_SMALLER                                               !6, !1
         35      > JMPNZ                                                    ~25, ->16
   11    36    > > RETURN                                                   !2
   12    37*     > RETURN                                                   null

End of function custom_chunk

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
142.89 ms | 1078 KiB | 18 Q