3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Everything you enter here will be executed by our servers. Try it! $data = array( array('a', 'b', 'c', 'd', 'e'), array('f', 'g', 'h', 'i', 'j'), array('k', 'l', 'm', 'n', 'o'), array('p', 'q', 'r') ); echo "<pre>"; print_r(array_chunk($data,4,true)); die(); $width = count($data[0]); // 5 $height = count($data); // 4 $total = $width * $height; // 20 $new_data = array(); for($i = 0; $i < $total; $i++) { $old_x = floor($i % $width); // integer division $old_y = $i / $width; // modulo $new_x = $i % $height; // modulo $new_y = floor($i / $height); // integer division if (!isset($new_data[$new_x])) { $new_data[$new_x] = array(); } if (isset($data[$old_x][$old_y])) { $new_data[$new_x][$new_y] = $data[$old_x][$old_y]; } } print_r($new_data);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 79) Position 1 = -2
filename:       /in/NXgKI
function name:  (null)
number of ops:  55
compiled vars:  !0 = $data, !1 = $width, !2 = $height, !3 = $total, !4 = $new_data, !5 = $i, !6 = $old_x, !7 = $old_y, !8 = $new_x, !9 = $new_y
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        ECHO                                                     '%3Cpre%3E'
   11     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'array_chunk'
          4        SEND_VAR                                                 !0
          5        SEND_VAL                                                 4
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $11     
          8        SEND_VAR                                                 $11
          9        DO_ICALL                                                 
   12    10      > EXIT                                                     
   14    11*       FETCH_DIM_R                                      ~13     !0, 0
         12*       COUNT                                            ~14     ~13
         13*       ASSIGN                                                   !1, ~14
   15    14*       COUNT                                            ~16     !0
         15*       ASSIGN                                                   !2, ~16
   16    16*       MUL                                              ~18     !1, !2
         17*       ASSIGN                                                   !3, ~18
   18    18*       ASSIGN                                                   !4, <array>
   20    19*       ASSIGN                                                   !5, 0
         20*       JMP                                                      ->49
   21    21*       INIT_FCALL                                               'floor'
         22*       MOD                                              ~22     !5, !1
         23*       SEND_VAL                                                 ~22
         24*       DO_ICALL                                         $23     
         25*       ASSIGN                                                   !6, $23
   22    26*       DIV                                              ~25     !5, !1
         27*       ASSIGN                                                   !7, ~25
   24    28*       MOD                                              ~27     !5, !2
         29*       ASSIGN                                                   !8, ~27
   25    30*       INIT_FCALL                                               'floor'
         31*       DIV                                              ~29     !5, !2
         32*       SEND_VAL                                                 ~29
         33*       DO_ICALL                                         $30     
         34*       ASSIGN                                                   !9, $30
   27    35*       ISSET_ISEMPTY_DIM_OBJ                         0  ~32     !4, !8
         36*       BOOL_NOT                                         ~33     ~32
         37*       JMPZ                                                     ~33, ->40
   28    38*       ASSIGN_DIM                                               !4, !8
         39*       OP_DATA                                                  <array>
   30    40*       FETCH_DIM_IS                                     ~35     !0, !6
         41*       ISSET_ISEMPTY_DIM_OBJ                         0          ~35, !7
         42*       JMPZ                                                     ~36, ->48
   31    43*       FETCH_DIM_R                                      ~39     !0, !6
         44*       FETCH_DIM_R                                      ~40     ~39, !7
         45*       FETCH_DIM_W                                      $37     !4, !8
         46*       ASSIGN_DIM                                               $37, !9
         47*       OP_DATA                                                  ~40
   20    48*       PRE_INC                                                  !5
         49*       IS_SMALLER                                               !5, !3
         50*       JMPNZ                                                    ~42, ->21
   34    51*       INIT_FCALL                                               'print_r'
         52*       SEND_VAR                                                 !4
         53*       DO_ICALL                                                 
         54*     > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.95 ms | 1400 KiB | 19 Q