3v4l.org

run code in 300+ PHP versions simultaneously
<?php function restructureArray1($array, $x) { $size = sizeof($array); if ($size < $x) return array_chunk($array, 1) + array_fill(0, $x, array()); $big_row_length = (int) ($size / $x) + 1; $big_rows_chunk = array_splice($array, 0, $size % $x * $big_row_length); return array_merge(array_chunk($big_rows_chunk, $big_row_length), array_chunk($array, $big_row_length - 1)); } function restructureArray2($array, $x) { $size = sizeof($array); $small_row_length = (int) ($size / $x); $big_row_count = $size % $x; for ($i = 0; $i < $x; ++$i) { $length = $small_row_length + (int) ($i < $big_row_count); $return [] = array_splice($array, 0, $length); } return $return; } $x = 3; $size = 7; $array = range(1, $size); $result1 = restructureArray1($array, $x); $result2 = restructureArray2($array, $x); var_dump(array_map(function($array) { return implode(', ', $array); }, $result2));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gJA7A
function name:  (null)
number of ops:  26
compiled vars:  !0 = $x, !1 = $size, !2 = $array, !3 = $result1, !4 = $result2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   ASSIGN                                                   !0, 3
   26     1        ASSIGN                                                   !1, 7
   27     2        INIT_FCALL                                               'range'
          3        SEND_VAL                                                 1
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $7      
          6        ASSIGN                                                   !2, $7
   28     7        INIT_FCALL                                               'restructurearray1'
          8        SEND_VAR                                                 !2
          9        SEND_VAR                                                 !0
         10        DO_FCALL                                      0  $9      
         11        ASSIGN                                                   !3, $9
   29    12        INIT_FCALL                                               'restructurearray2'
         13        SEND_VAR                                                 !2
         14        SEND_VAR                                                 !0
         15        DO_FCALL                                      0  $11     
         16        ASSIGN                                                   !4, $11
   30    17        INIT_FCALL                                               'var_dump'
         18        INIT_FCALL                                               'array_map'
         19        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FgJA7A%3A30%240'
   31    20        SEND_VAL                                                 ~13
         21        SEND_VAR                                                 !4
         22        DO_ICALL                                         $14     
         23        SEND_VAR                                                 $14
         24        DO_ICALL                                                 
         25      > RETURN                                                   1

Function restructurearray1:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 17
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gJA7A
function name:  restructureArray1
number of ops:  44
compiled vars:  !0 = $array, !1 = $x, !2 = $size, !3 = $big_row_length, !4 = $big_rows_chunk
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        COUNT                                            ~5      !0
          3        ASSIGN                                                   !2, ~5
    5     4        IS_SMALLER                                               !2, !1
          5      > JMPZ                                                     ~7, ->17
    6     6    >   INIT_FCALL                                               'array_chunk'
          7        SEND_VAR                                                 !0
          8        SEND_VAL                                                 1
          9        DO_ICALL                                         $8      
         10        INIT_FCALL                                               'array_fill'
         11        SEND_VAL                                                 0
         12        SEND_VAR                                                 !1
         13        SEND_VAL                                                 <array>
         14        DO_ICALL                                         $9      
         15        ADD                                              ~10     $8, $9
         16      > RETURN                                                   ~10
    7    17    >   DIV                                              ~11     !2, !1
         18        CAST                                          4  ~12     ~11
         19        ADD                                              ~13     ~12, 1
         20        ASSIGN                                                   !3, ~13
    8    21        INIT_FCALL                                               'array_splice'
         22        SEND_REF                                                 !0
         23        SEND_VAL                                                 0
         24        MOD                                              ~15     !2, !1
         25        MUL                                              ~16     !3, ~15
         26        SEND_VAL                                                 ~16
         27        DO_ICALL                                         $17     
         28        ASSIGN                                                   !4, $17
    9    29        INIT_FCALL                                               'array_merge'
         30        INIT_FCALL                                               'array_chunk'
         31        SEND_VAR                                                 !4
         32        SEND_VAR                                                 !3
         33        DO_ICALL                                         $19     
         34        SEND_VAR                                                 $19
         35        INIT_FCALL                                               'array_chunk'
         36        SEND_VAR                                                 !0
         37        SUB                                              ~20     !3, 1
         38        SEND_VAL                                                 ~20
         39        DO_ICALL                                         $21     
         40        SEND_VAR                                                 $21
         41        DO_ICALL                                         $22     
         42      > RETURN                                                   $22
   10    43*     > RETURN                                                   null

End of function restructurearray1

Function restructurearray2:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 11
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 11
Branch analysis from position: 25
Branch analysis from position: 11
filename:       /in/gJA7A
function name:  restructureArray2
number of ops:  27
compiled vars:  !0 = $array, !1 = $x, !2 = $size, !3 = $small_row_length, !4 = $big_row_count, !5 = $i, !6 = $length, !7 = $return
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   14     2        COUNT                                            ~8      !0
          3        ASSIGN                                                   !2, ~8
   15     4        DIV                                              ~10     !2, !1
          5        CAST                                          4  ~11     ~10
          6        ASSIGN                                                   !3, ~11
   16     7        MOD                                              ~13     !2, !1
          8        ASSIGN                                                   !4, ~13
   17     9        ASSIGN                                                   !5, 0
         10      > JMP                                                      ->23
   19    11    >   IS_SMALLER                                       ~16     !5, !4
         12        CAST                                          4  ~17     ~16
         13        ADD                                              ~18     !3, ~17
         14        ASSIGN                                                   !6, ~18
   20    15        INIT_FCALL                                               'array_splice'
         16        SEND_REF                                                 !0
         17        SEND_VAL                                                 0
         18        SEND_VAR                                                 !6
         19        DO_ICALL                                         $21     
         20        ASSIGN_DIM                                               !7
         21        OP_DATA                                                  $21
   17    22        PRE_INC                                                  !5
         23    >   IS_SMALLER                                               !5, !1
         24      > JMPNZ                                                    ~23, ->11
   22    25    > > RETURN                                                   !7
   23    26*     > RETURN                                                   null

End of function restructurearray2

Function %00%7Bclosure%7D%2Fin%2FgJA7A%3A30%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/gJA7A
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   30     0  E >   RECV                                             !0      
   31     1        INIT_FCALL                                               'implode'
          2        SEND_VAL                                                 '%2C+'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $1      
          5      > RETURN                                                   $1
          6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FgJA7A%3A30%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
154.34 ms | 1407 KiB | 31 Q