3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_chunk_vertical($data, $columns = 2) { $n = count($data) ; $per_column = floor($n / $columns) ; $rest = $n % $columns ; // The map $per_columns = array( ) ; for ( $i = 0 ; $i < $columns ; $i++ ) { $per_columns[$i] = $per_column + ($i < $rest ? 1 : 0) ; } $tabular = array( ) ; foreach ( $per_columns as $rows ) { for ( $i = 0 ; $i < $rows ; $i++ ) { $tabular[$i][ ] = array_shift($data) ; } } return $tabular ; } $cars = [ [ 'make' => 'Alfa Romeo', 'id' => 2 ], [ 'make' => 'Aston Martin', 'id' => 3 ], [ 'make' => 'Audi', 'id' => 4 ], [ 'make' => 'BMW', 'id' => 8 ], [ 'make' => 'Caterham', 'id' => 9 ], ]; echo '<table>'; foreach(array_chunk_vertical($cars,4) as $row) { echo '<tr>'; foreach($row as $car) { echo '<td><input type="checkbox" value="', $car['id'], '" />', $car['make'], '</td>'; } echo '</tr>'; } echo '</table>';
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 22
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 22
Branch analysis from position: 8
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 19
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 19
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/3pEBi
function name:  (null)
number of ops:  25
compiled vars:  !0 = $cars, !1 = $row, !2 = $car
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, <array>
   33     1        ECHO                                                     '%3Ctable%3E'
   34     2        INIT_FCALL                                               'array_chunk_vertical'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 4
          5        DO_FCALL                                      0  $4      
          6      > FE_RESET_R                                       $5      $4, ->22
          7    > > FE_FETCH_R                                               $5, !1, ->22
   35     8    >   ECHO                                                     '%3Ctr%3E'
   36     9      > FE_RESET_R                                       $6      !1, ->19
         10    > > FE_FETCH_R                                               $6, !2, ->19
   37    11    >   ECHO                                                     '%3Ctd%3E%3Cinput+type%3D%22checkbox%22+value%3D%22'
         12        FETCH_DIM_R                                      ~7      !2, 'id'
         13        ECHO                                                     ~7
         14        ECHO                                                     '%22+%2F%3E'
         15        FETCH_DIM_R                                      ~8      !2, 'make'
         16        ECHO                                                     ~8
         17        ECHO                                                     '%3C%2Ftd%3E'
   36    18      > JMP                                                      ->10
         19    >   FE_FREE                                                  $6
   39    20        ECHO                                                     '%3C%2Ftr%3E'
   34    21      > JMP                                                      ->7
         22    >   FE_FREE                                                  $5
   42    23        ECHO                                                     '%3C%2Ftable%3E'
         24      > RETURN                                                   1

Function array_chunk_vertical:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 14
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 27, Position 2 = 40
Branch analysis from position: 27
2 jumps found. (Code = 78) Position 1 = 28, Position 2 = 40
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 30
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 30
Branch analysis from position: 39
Branch analysis from position: 30
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 14
Branch analysis from position: 25
Branch analysis from position: 14
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 14
Branch analysis from position: 25
Branch analysis from position: 14
filename:       /in/3pEBi
function name:  array_chunk_vertical
number of ops:  43
compiled vars:  !0 = $data, !1 = $columns, !2 = $n, !3 = $per_column, !4 = $rest, !5 = $per_columns, !6 = $i, !7 = $tabular, !8 = $rows
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
    4     2        COUNT                                            ~9      !0
          3        ASSIGN                                                   !2, ~9
    5     4        INIT_FCALL                                               'floor'
          5        DIV                                              ~11     !2, !1
          6        SEND_VAL                                                 ~11
          7        DO_ICALL                                         $12     
          8        ASSIGN                                                   !3, $12
    6     9        MOD                                              ~14     !2, !1
         10        ASSIGN                                                   !4, ~14
    9    11        ASSIGN                                                   !5, <array>
   10    12        ASSIGN                                                   !6, 0
         13      > JMP                                                      ->23
   11    14    >   IS_SMALLER                                               !6, !4
         15      > JMPZ                                                     ~19, ->18
         16    >   QM_ASSIGN                                        ~20     1
         17      > JMP                                                      ->19
         18    >   QM_ASSIGN                                        ~20     0
         19    >   ADD                                              ~21     !3, ~20
         20        ASSIGN_DIM                                               !5, !6
         21        OP_DATA                                                  ~21
   10    22        PRE_INC                                                  !6
         23    >   IS_SMALLER                                               !6, !1
         24      > JMPNZ                                                    ~23, ->14
   14    25    >   ASSIGN                                                   !7, <array>
   15    26      > FE_RESET_R                                       $25     !5, ->40
         27    > > FE_FETCH_R                                               $25, !8, ->40
   16    28    >   ASSIGN                                                   !6, 0
         29      > JMP                                                      ->37
   17    30    >   INIT_FCALL                                               'array_shift'
         31        SEND_REF                                                 !0
         32        DO_ICALL                                         $29     
         33        FETCH_DIM_W                                      $27     !7, !6
         34        ASSIGN_DIM                                               $27
         35        OP_DATA                                                  $29
   16    36        PRE_INC                                                  !6
         37    >   IS_SMALLER                                               !6, !8
         38      > JMPNZ                                                    ~31, ->30
   15    39    > > JMP                                                      ->27
         40    >   FE_FREE                                                  $25
   21    41      > RETURN                                                   !7
   22    42*     > RETURN                                                   null

End of function array_chunk_vertical

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.49 ms | 1406 KiB | 18 Q