3v4l.org

run code in 300+ PHP versions simultaneously
<?php function restructure($x,$slots) { $result=array(); $count=count($x); $least=(int)($count/$slots); $excess=$count-$least*$slots; for($i=0;$i<($least+1)*$excess;$i+=$least+1) array_push($result,implode(", ",array_slice($x,$i,$least+1))); for(;$i<$count;$i+=$least) array_push($result,implode(", ",array_slice($x,$i,$least))); return $result; } $x=array( "item 1", "item 2", "item 3", "item 4", "item 5", "item 6", "item 7", ); print_r(restructure($x,5));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/hIVfb
function name:  (null)
number of ops:  9
compiled vars:  !0 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   ASSIGN                                                   !0, <array>
   26     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'restructure'
          3        SEND_VAR                                                 !0
          4        SEND_VAL                                                 5
          5        DO_FCALL                                      0  $2      
          6        SEND_VAR                                                 $2
          7        DO_ICALL                                                 
          8      > RETURN                                                   1

Function restructure:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 13
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 34
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 34
Branch analysis from position: 50
Branch analysis from position: 34
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 13
Branch analysis from position: 33
Branch analysis from position: 13
filename:       /in/hIVfb
function name:  restructure
number of ops:  52
compiled vars:  !0 = $x, !1 = $slots, !2 = $result, !3 = $count, !4 = $least, !5 = $excess, !6 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    5     3        COUNT                                            ~8      !0
          4        ASSIGN                                                   !3, ~8
    7     5        DIV                                              ~10     !3, !1
          6        CAST                                          4  ~11     ~10
          7        ASSIGN                                                   !4, ~11
    8     8        MUL                                              ~13     !4, !1
          9        SUB                                              ~14     !3, ~13
         10        ASSIGN                                                   !5, ~14
   10    11        ASSIGN                                                   !6, 0
         12      > JMP                                                      ->29
   11    13    >   INIT_FCALL                                               'array_push'
         14        SEND_REF                                                 !2
         15        INIT_FCALL                                               'implode'
         16        SEND_VAL                                                 '%2C+'
         17        INIT_FCALL                                               'array_slice'
         18        SEND_VAR                                                 !0
         19        SEND_VAR                                                 !6
         20        ADD                                              ~17     !4, 1
         21        SEND_VAL                                                 ~17
         22        DO_ICALL                                         $18     
         23        SEND_VAR                                                 $18
         24        DO_ICALL                                         $19     
         25        SEND_VAR                                                 $19
         26        DO_ICALL                                                 
   10    27        ADD                                              ~21     !4, 1
         28        ASSIGN_OP                                     1          !6, ~21
         29    >   ADD                                              ~23     !4, 1
         30        MUL                                              ~24     !5, ~23
         31        IS_SMALLER                                               !6, ~24
         32      > JMPNZ                                                    ~25, ->13
   12    33    > > JMP                                                      ->48
   13    34    >   INIT_FCALL                                               'array_push'
         35        SEND_REF                                                 !2
         36        INIT_FCALL                                               'implode'
         37        SEND_VAL                                                 '%2C+'
         38        INIT_FCALL                                               'array_slice'
         39        SEND_VAR                                                 !0
         40        SEND_VAR                                                 !6
         41        SEND_VAR                                                 !4
         42        DO_ICALL                                         $26     
         43        SEND_VAR                                                 $26
         44        DO_ICALL                                         $27     
         45        SEND_VAR                                                 $27
         46        DO_ICALL                                                 
   12    47        ASSIGN_OP                                     1          !6, !4
         48    >   IS_SMALLER                                               !6, !3
         49      > JMPNZ                                                    ~30, ->34
   14    50    > > RETURN                                                   !2
   15    51*     > RETURN                                                   null

End of function restructure

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
137.67 ms | 1008 KiB | 18 Q