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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.21 ms | 1392 KiB | 17 Q