3v4l.org

run code in 300+ PHP versions simultaneously
<?php $matrix = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16], // [17, 18, 19, 20] ]; $r = 1; matrixRotation($matrix, $r); function matrixRotation($matrix, $r) { $m = new Matrix($matrix); $m->rotate(); // print_r($m->get()); } class Matrix { private $mx; private $m; private $n; private $a; // i [a,b] private $b; private $c; // j [c,d] private $d; public function get() { return $this->mx; } public function __construct($mx) { try { $this->set($mx); } catch(\Exception $e) { echo $e->getMessage(); // exit(1); } } private function set(array $mx) { $this->m = count($mx); $this->n = count($mx[0]); $this->a = 0; $this->b = $this->m-1; $this->c = 0; $this->d = $this->n-1; $this->mx = $mx; } public function rotate($r = 1) { $k = 0; while(1) { $this->a += $k; $this->b -= $k; $this->c += $k; $this->d -= $k; var_dump($this->a, $this->b,$this->c,$this->d); break; if ( $this->a === $this->b || $this->c === $this->d ) { break; } $mult = 2*($this->m-2*$k)+2*($this->n-2*$k)-4; $rm = $r % $mult; while($rm--) { print_r('rotateSquare'.PHP_EOL); // $this->rotateSquare(); } ++$k; } } private function rotateSquare() { $t = []; //transite for($i=0; $i<$this->m; ++$i) { for($j=0; $j<$this->n; ++$j) { $t[$i][$j] = [0,0]; } } $j=$this->c; for($i=$this->a; $i<$this->b; ++$i) { $t[$i][$j] = [-1,0]; } $i=$this->b; for($j=$this->c; $j<$this->d; ++$j) { $t[$i][$j] = [0,1]; } $j=$this->d; for($i=$this->b; $i>$this->a; --$i) { $t[$i][$j] = [1,0]; } $i=$this->a; for($j=$this->d; $j<$this->c; --$j) { $t[$i][$j] = [0,-1]; } prtint_r($t); // $temp = []; // for($i=0; $i<$this->m; ++$i) { // for($j=0; $j<$this->n; ++$j) { // $iOffset = $t[$i][$j][0]; // $jOffset = $t[$i][$j][1]; // $temp[$i+$iOffset][$j+$jOffset] = $this->mx[$i][$j]; // } // } // $this->mx = $this->ksort($temp); // return $this; } private function ksort($temp) { foreach($temp as &$ar){ ksort($ar); } ksort($temp); return $temp; } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OHsde
function name:  (null)
number of ops:  7
compiled vars:  !0 = $matrix, !1 = $r
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    9     1        ASSIGN                                                   !1, 1
   11     2        INIT_FCALL_BY_NAME                                       'matrixRotation'
          3        SEND_VAR_EX                                              !0
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
  130     6      > RETURN                                                   1

Function matrixrotation:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OHsde
function name:  matrixRotation
number of ops:  9
compiled vars:  !0 = $matrix, !1 = $r, !2 = $m
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        NEW                                              $3      'Matrix'
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $3
   15     6        INIT_METHOD_CALL                                         !2, 'rotate'
          7        DO_FCALL                                      0          
   17     8      > RETURN                                                   null

End of function matrixrotation

Class Matrix:
Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OHsde
function name:  get
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   FETCH_OBJ_R                                      ~0      'mx'
          1      > RETURN                                                   ~0
   32     2*     > RETURN                                                   null

End of function get

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Found catch point at position: 5
Branch analysis from position: 5
2 jumps found. (Code = 107) Position 1 = 6, Position 2 = -2
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OHsde
function name:  __construct
number of ops:  10
compiled vars:  !0 = $mx, !1 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   36     1        INIT_METHOD_CALL                                         'set'
          2        SEND_VAR_EX                                              !0
          3        DO_FCALL                                      0          
          4      > JMP                                                      ->9
   37     5  E > > CATCH                                       last         'Exception'
   38     6    >   INIT_METHOD_CALL                                         !1, 'getMessage'
          7        DO_FCALL                                      0  $3      
          8        ECHO                                                     $3
   41     9    > > RETURN                                                   null

End of function __construct

Function set:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OHsde
function name:  set
number of ops:  23
compiled vars:  !0 = $mx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   43     0  E >   RECV                                             !0      
   44     1        COUNT                                            ~2      !0
          2        ASSIGN_OBJ                                               'm'
          3        OP_DATA                                                  ~2
   45     4        FETCH_DIM_R                                      ~4      !0, 0
          5        COUNT                                            ~5      ~4
          6        ASSIGN_OBJ                                               'n'
          7        OP_DATA                                                  ~5
   47     8        ASSIGN_OBJ                                               'a'
          9        OP_DATA                                                  0
   48    10        FETCH_OBJ_R                                      ~8      'm'
         11        SUB                                              ~9      ~8, 1
         12        ASSIGN_OBJ                                               'b'
         13        OP_DATA                                                  ~9
   49    14        ASSIGN_OBJ                                               'c'
         15        OP_DATA                                                  0
   50    16        FETCH_OBJ_R                                      ~12     'n'
         17        SUB                                              ~13     ~12, 1
         18        ASSIGN_OBJ                                               'd'
         19        OP_DATA                                                  ~13
   52    20        ASSIGN_OBJ                                               'mx'
         21        OP_DATA                                                  !0
   53    22      > RETURN                                                   null

End of function set

Function rotate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 52
Branch analysis from position: 52
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 3
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
filename:       /in/OHsde
function name:  rotate
number of ops:  54
compiled vars:  !0 = $r, !1 = $k, !2 = $mult, !3 = $rm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   55     0  E >   RECV_INIT                                        !0      1
   56     1        ASSIGN                                                   !1, 0
   57     2      > JMP                                                      ->52
   58     3    >   ASSIGN_OBJ_OP                                 1          'a'
          4        OP_DATA                                                  !1
   59     5        ASSIGN_OBJ_OP                                 2          'b'
          6        OP_DATA                                                  !1
   60     7        ASSIGN_OBJ_OP                                 1          'c'
          8        OP_DATA                                                  !1
   61     9        ASSIGN_OBJ_OP                                 2          'd'
         10        OP_DATA                                                  !1
   62    11        INIT_FCALL                                               'var_dump'
         12        FETCH_OBJ_R                                      ~9      'a'
         13        SEND_VAL                                                 ~9
         14        FETCH_OBJ_R                                      ~10     'b'
         15        SEND_VAL                                                 ~10
         16        FETCH_OBJ_R                                      ~11     'c'
         17        SEND_VAL                                                 ~11
         18        FETCH_OBJ_R                                      ~12     'd'
         19        SEND_VAL                                                 ~12
         20        DO_ICALL                                                 
   63    21      > JMP                                                      ->53
   65    22*       FETCH_OBJ_R                                      ~14     'a'
         23*       FETCH_OBJ_R                                      ~15     'b'
         24*       IS_IDENTICAL                                     ~16     ~14, ~15
         25*       JMPNZ_EX                                         ~16     ~16, ->30
   66    26*       FETCH_OBJ_R                                      ~17     'c'
         27*       FETCH_OBJ_R                                      ~18     'd'
         28*       IS_IDENTICAL                                     ~19     ~17, ~18
         29*       BOOL                                             ~16     ~19
         30*       JMPZ                                                     ~16, ->32
   68    31*       JMP                                                      ->53
   70    32*       FETCH_OBJ_R                                      ~20     'm'
         33*       MUL                                              ~21     !1, 2
         34*       SUB                                              ~22     ~20, ~21
         35*       MUL                                              ~23     ~22, 2
         36*       FETCH_OBJ_R                                      ~24     'n'
         37*       MUL                                              ~25     !1, 2
         38*       SUB                                              ~26     ~24, ~25
         39*       MUL                                              ~27     ~26, 2
         40*       ADD                                              ~28     ~23, ~27
         41*       SUB                                              ~29     ~28, 4
         42*       ASSIGN                                                   !2, ~29
   71    43*       MOD                                              ~31     !0, !2
         44*       ASSIGN                                                   !3, ~31
   72    45*       JMP                                                      ->49
   73    46*       INIT_FCALL                                               'print_r'
         47*       SEND_VAL                                                 'rotateSquare%0A'
         48*       DO_ICALL                                                 
   72    49*       POST_DEC                                         ~34     !3
         50*       JMPNZ                                                    ~34, ->46
   76    51*       PRE_INC                                                  !1
   57    52    > > JMPNZ                                                    1, ->3
   78    53    > > RETURN                                                   null

End of function rotate

Function rotatesquare:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 3
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 25
Branch analysis from position: 25
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 21
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 = 40, Position 2 = 33
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 45
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 57
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 57
Branch analysis from position: 64
Branch analysis from position: 57
Branch analysis from position: 45
2 jumps found. (Code = 44) Position 1 = 52, Position 2 = 45
Branch analysis from position: 52
Branch analysis from position: 45
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 33
Branch analysis from position: 40
Branch analysis from position: 33
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 28, Position 2 = 21
Branch analysis from position: 28
Branch analysis from position: 21
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 5
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 3
Branch analysis from position: 16
Branch analysis from position: 3
Branch analysis from position: 5
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 5
Branch analysis from position: 12
Branch analysis from position: 5
filename:       /in/OHsde
function name:  rotateSquare
number of ops:  68
compiled vars:  !0 = $t, !1 = $i, !2 = $j
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   ASSIGN                                                   !0, <array>
   83     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->13
   84     3    >   ASSIGN                                                   !2, 0
          4      > JMP                                                      ->9
   85     5    >   FETCH_DIM_W                                      $6      !0, !1
          6        ASSIGN_DIM                                               $6, !2
          7        OP_DATA                                                  <array>
   84     8        PRE_INC                                                  !2
          9    >   FETCH_OBJ_R                                      ~9      'n'
         10        IS_SMALLER                                               !2, ~9
         11      > JMPNZ                                                    ~10, ->5
   83    12    >   PRE_INC                                                  !1
         13    >   FETCH_OBJ_R                                      ~12     'm'
         14        IS_SMALLER                                               !1, ~12
         15      > JMPNZ                                                    ~13, ->3
   89    16    >   FETCH_OBJ_R                                      ~14     'c'
         17        ASSIGN                                                   !2, ~14
   90    18        FETCH_OBJ_R                                      ~16     'a'
         19        ASSIGN                                                   !1, ~16
         20      > JMP                                                      ->25
   91    21    >   FETCH_DIM_W                                      $18     !0, !1
         22        ASSIGN_DIM                                               $18, !2
         23        OP_DATA                                                  <array>
   90    24        PRE_INC                                                  !1
         25    >   FETCH_OBJ_R                                      ~21     'b'
         26        IS_SMALLER                                               !1, ~21
         27      > JMPNZ                                                    ~22, ->21
   93    28    >   FETCH_OBJ_R                                      ~23     'b'
         29        ASSIGN                                                   !1, ~23
   94    30        FETCH_OBJ_R                                      ~25     'c'
         31        ASSIGN                                                   !2, ~25
         32      > JMP                                                      ->37
   95    33    >   FETCH_DIM_W                                      $27     !0, !1
         34        ASSIGN_DIM                                               $27, !2
         35        OP_DATA                                                  <array>
   94    36        PRE_INC                                                  !2
         37    >   FETCH_OBJ_R                                      ~30     'd'
         38        IS_SMALLER                                               !2, ~30
         39      > JMPNZ                                                    ~31, ->33
   97    40    >   FETCH_OBJ_R                                      ~32     'd'
         41        ASSIGN                                                   !2, ~32
   98    42        FETCH_OBJ_R                                      ~34     'b'
         43        ASSIGN                                                   !1, ~34
         44      > JMP                                                      ->49
   99    45    >   FETCH_DIM_W                                      $36     !0, !1
         46        ASSIGN_DIM                                               $36, !2
         47        OP_DATA                                                  <array>
   98    48        PRE_DEC                                                  !1
         49    >   FETCH_OBJ_R                                      ~39     'a'
         50        IS_SMALLER                                               ~39, !1
         51      > JMPNZ                                                    ~40, ->45
  101    52    >   FETCH_OBJ_R                                      ~41     'a'
         53        ASSIGN                                                   !1, ~41
  102    54        FETCH_OBJ_R                                      ~43     'd'
         55        ASSIGN                                                   !2, ~43
         56      > JMP                                                      ->61
  103    57    >   FETCH_DIM_W                                      $45     !0, !1
         58        ASSIGN_DIM                                               $45, !2
         59        OP_DATA                                                  <array>
  102    60        PRE_DEC                                                  !2
         61    >   FETCH_OBJ_R                                      ~48     'c'
         62        IS_SMALLER                                               !2, ~48
         63      > JMPNZ                                                    ~49, ->57
  106    64    >   INIT_FCALL_BY_NAME                                       'prtint_r'
         65        SEND_VAR_EX                                              !0
         66        DO_FCALL                                      0          
  120    67      > RETURN                                                   null

End of function rotatesquare

Function ksort:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
2 jumps found. (Code = 126) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/OHsde
function name:  ksort
number of ops:  13
compiled vars:  !0 = $temp, !1 = $ar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  122     0  E >   RECV                                             !0      
  123     1      > FE_RESET_RW                                      $2      !0, ->7
          2    > > FE_FETCH_RW                                              $2, !1, ->7
  124     3    >   INIT_FCALL                                               'ksort'
          4        SEND_REF                                                 !1
          5        DO_ICALL                                                 
  123     6      > JMP                                                      ->2
          7    >   FE_FREE                                                  $2
  126     8        INIT_FCALL                                               'ksort'
          9        SEND_REF                                                 !0
         10        DO_ICALL                                                 
  128    11      > RETURN                                                   !0
  129    12*     > RETURN                                                   null

End of function ksort

End of class Matrix.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
129.34 ms | 1421 KiB | 19 Q