3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_make_square(array &$array, $fill = ' ') { $pad = count(array_keys($array)); foreach ($array as &$row) { $row = array_pad($row, $pad, $fill); } } function array_organize(array &$outer) { $offset = 0; foreach ($outer as &$inner) { sort($inner); array_rotate($inner, $offset++); } } function array_rotate(array &$array, $offset) { foreach (array_slice($array, 0, $offset, true) as $key => $val) { unset($array[$key]); $array[$key] = $val; } } function solve($test) { array_make_square($test); array_organize($test); return $test; } function display($outer) { echo "[\n"; foreach ($outer as $row => $inner) { echo " $row => ['" . implode("', '", $inner) . "']\n"; } echo "]\n"; } $tests = [ [ ['X'], ['X'], ['X'] ], [ ['X', 'Y'], ['X', 'Y'], ['X', 'Y'] ], [ ['X', 'Y', 'Z'], ['X', 'Y', 'Z'], ['X', 'Y', 'Z'] ], ]; array_map('display', array_map('solve', $tests));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/joZNJ
function name:  (null)
number of ops:  10
compiled vars:  !0 = $tests
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   ASSIGN                                                   !0, <array>
   44     1        INIT_FCALL                                               'array_map'
          2        SEND_VAL                                                 'display'
          3        INIT_FCALL                                               'array_map'
          4        SEND_VAL                                                 'solve'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function array_make_square:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
2 jumps found. (Code = 126) Position 1 = 9, Position 2 = 16
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/joZNJ
function name:  array_make_square
number of ops:  18
compiled vars:  !0 = $array, !1 = $fill, !2 = $pad, !3 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      '+'
    4     2        INIT_FCALL                                               'array_keys'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $4      
          5        COUNT                                            ~5      $4
          6        ASSIGN                                                   !2, ~5
    5     7      > FE_RESET_RW                                      $7      !0, ->16
          8    > > FE_FETCH_RW                                              $7, !3, ->16
    6     9    >   INIT_FCALL                                               'array_pad'
         10        SEND_VAR                                                 !3
         11        SEND_VAR                                                 !2
         12        SEND_VAR                                                 !1
         13        DO_ICALL                                         $8      
         14        ASSIGN                                                   !3, $8
    5    15      > JMP                                                      ->8
         16    >   FE_FREE                                                  $7
    8    17      > RETURN                                                   null

End of function array_make_square

Function array_organize:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 3, Position 2 = 13
Branch analysis from position: 3
2 jumps found. (Code = 126) Position 1 = 4, Position 2 = 13
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/joZNJ
function name:  array_organize
number of ops:  15
compiled vars:  !0 = $outer, !1 = $offset, !2 = $inner
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
   11     1        ASSIGN                                                   !1, 0
   12     2      > FE_RESET_RW                                      $4      !0, ->13
          3    > > FE_FETCH_RW                                              $4, !2, ->13
   13     4    >   INIT_FCALL                                               'sort'
          5        SEND_REF                                                 !2
          6        DO_ICALL                                                 
   14     7        INIT_FCALL_BY_NAME                                       'array_rotate'
          8        SEND_VAR_EX                                              !2
          9        POST_INC                                         ~6      !1
         10        SEND_VAL_EX                                              ~6
         11        DO_FCALL                                      0          
   12    12      > JMP                                                      ->3
         13    >   FE_FREE                                                  $4
   16    14      > RETURN                                                   null

End of function array_organize

Function array_rotate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 15
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 15
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
filename:       /in/joZNJ
function name:  array_rotate
number of ops:  17
compiled vars:  !0 = $array, !1 = $offset, !2 = $val, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   19     2        INIT_FCALL                                               'array_slice'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 0
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $4      
          8      > FE_RESET_R                                       $5      $4, ->15
          9    > > FE_FETCH_R                                       ~6      $5, !2, ->15
         10    >   ASSIGN                                                   !3, ~6
   20    11        UNSET_DIM                                                !0, !3
   21    12        ASSIGN_DIM                                               !0, !3
         13        OP_DATA                                                  !2
   19    14      > JMP                                                      ->9
         15    >   FE_FREE                                                  $5
   23    16      > RETURN                                                   null

End of function array_rotate

Function solve:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/joZNJ
function name:  solve
number of ops:  9
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   RECV                                             !0      
   26     1        INIT_FCALL                                               'array_make_square'
          2        SEND_REF                                                 !0
          3        DO_FCALL                                      0          
   27     4        INIT_FCALL                                               'array_organize'
          5        SEND_REF                                                 !0
          6        DO_FCALL                                      0          
   28     7      > RETURN                                                   !0
   29     8*     > RETURN                                                   null

End of function solve

Function display:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 16
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/joZNJ
function name:  display
number of ops:  19
compiled vars:  !0 = $outer, !1 = $inner, !2 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
   32     1        ECHO                                                     '%5B%0A'
   33     2      > FE_RESET_R                                       $3      !0, ->16
          3    > > FE_FETCH_R                                       ~4      $3, !1, ->16
          4    >   ASSIGN                                                   !2, ~4
   34     5        ROPE_INIT                                     3  ~7      '++'
          6        ROPE_ADD                                      1  ~7      ~7, !2
          7        ROPE_END                                      2  ~6      ~7, '+%3D%3E+%5B%27'
          8        INIT_FCALL                                               'implode'
          9        SEND_VAL                                                 '%27%2C+%27'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $9      
         12        CONCAT                                           ~10     ~6, $9
         13        CONCAT                                           ~11     ~10, '%27%5D%0A'
         14        ECHO                                                     ~11
   33    15      > JMP                                                      ->3
         16    >   FE_FREE                                                  $3
   36    17        ECHO                                                     '%5D%0A'
   37    18      > RETURN                                                   null

End of function display

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
177.57 ms | 1411 KiB | 27 Q