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 = 42) Position 1 = 40
Branch analysis from position: 40
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 12
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 31
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 39
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 12
Branch analysis from position: 42
Branch analysis from position: 12
Branch analysis from position: 39
Branch analysis from position: 31
filename:       /in/1oRG7
function name:  (null)
number of ops:  46
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'
   14     2        FETCH_DIM_R                                      ~11     !0, 0
          3        COUNT                                            ~12     ~11
          4        ASSIGN                                                   !1, ~12
   15     5        COUNT                                            ~14     !0
          6        ASSIGN                                                   !2, ~14
   16     7        MUL                                              ~16     !1, !2
          8        ASSIGN                                                   !3, ~16
   18     9        ASSIGN                                                   !4, <array>
   20    10        ASSIGN                                                   !5, 0
         11      > JMP                                                      ->40
   21    12    >   INIT_FCALL                                               'floor'
         13        MOD                                              ~20     !5, !1
         14        SEND_VAL                                                 ~20
         15        DO_ICALL                                         $21     
         16        ASSIGN                                                   !6, $21
   22    17        DIV                                              ~23     !5, !1
         18        ASSIGN                                                   !7, ~23
   24    19        MOD                                              ~25     !5, !2
         20        ASSIGN                                                   !8, ~25
   25    21        INIT_FCALL                                               'floor'
         22        DIV                                              ~27     !5, !2
         23        SEND_VAL                                                 ~27
         24        DO_ICALL                                         $28     
         25        ASSIGN                                                   !9, $28
   27    26        ISSET_ISEMPTY_DIM_OBJ                         0  ~30     !4, !8
         27        BOOL_NOT                                         ~31     ~30
         28      > JMPZ                                                     ~31, ->31
   28    29    >   ASSIGN_DIM                                               !4, !8
         30        OP_DATA                                                  <array>
   30    31    >   FETCH_DIM_IS                                     ~33     !0, !6
         32        ISSET_ISEMPTY_DIM_OBJ                         0          ~33, !7
         33      > JMPZ                                                     ~34, ->39
   31    34    >   FETCH_DIM_R                                      ~37     !0, !6
         35        FETCH_DIM_R                                      ~38     ~37, !7
         36        FETCH_DIM_W                                      $35     !4, !8
         37        ASSIGN_DIM                                               $35, !9
         38        OP_DATA                                                  ~38
   20    39    >   PRE_INC                                                  !5
         40    >   IS_SMALLER                                               !5, !3
         41      > JMPNZ                                                    ~40, ->12
   34    42    >   INIT_FCALL                                               'print_r'
         43        SEND_VAR                                                 !4
         44        DO_ICALL                                                 
         45      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.27 ms | 1400 KiB | 17 Q