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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.2 ms | 1400 KiB | 17 Q