3v4l.org

run code in 300+ PHP versions simultaneously
<?php function littleEndianMinChunk(array $array, int $minChunkSize): array { if ($minChunkSize < 1) { throw new InvalidArgumentException('$minChunkSize must be 1 or greater'); } if (count($array) < $minChunkSize) { throw new InvalidArgumentException('$minChunkSize must not be less than the size of $array'); } $result = []; while ($array) { $count = count($array); $modulus = $count % $minChunkSize; if (!$modulus) { array_unshift($result, ...array_chunk($array, $minChunkSize)); break; } $expectedRemainingChunks = max(1, intdiv($count, $minChunkSize)); $sizeIncrease = ceil($modulus / $expectedRemainingChunks); array_unshift($result, array_splice($array, -$minChunkSize - $sizeIncrease)); } return $result; } $arraySize = 13; for ($n = 1; $n <= $arraySize; ++$n) { echo "arraySize $n \n"; $array = range(1, $n); for ($x = 1; $x <= 13; ++$x) { echo "chunkSize $x: "; try { echo json_encode(littleEndianMinChunk($array, $x)) . "\n"; } catch (Exception $e) { echo $e->getMessage() . "\n"; } } }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 3
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 14
Branch analysis from position: 36
2 jumps found. (Code = 44) Position 1 = 39, Position 2 = 3
Branch analysis from position: 39
Branch analysis from position: 3
Branch analysis from position: 14
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 14
Branch analysis from position: 36
Branch analysis from position: 14
Found catch point at position: 28
Branch analysis from position: 28
2 jumps found. (Code = 107) Position 1 = 29, Position 2 = -2
Branch analysis from position: 29
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 14
Branch analysis from position: 36
Branch analysis from position: 14
filename:       /in/BbcfI
function name:  (null)
number of ops:  40
compiled vars:  !0 = $arraySize, !1 = $n, !2 = $array, !3 = $x, !4 = $e
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, 13
   27     1        ASSIGN                                                   !1, 1
          2      > JMP                                                      ->37
   28     3    >   ROPE_INIT                                     3  ~8      'arraySize+'
          4        ROPE_ADD                                      1  ~8      ~8, !1
          5        ROPE_END                                      2  ~7      ~8, '+%0A'
          6        ECHO                                                     ~7
   29     7        INIT_FCALL                                               'range'
          8        SEND_VAL                                                 1
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $10     
         11        ASSIGN                                                   !2, $10
   30    12        ASSIGN                                                   !3, 1
         13      > JMP                                                      ->34
   31    14    >   ROPE_INIT                                     3  ~14     'chunkSize+'
         15        ROPE_ADD                                      1  ~14     ~14, !3
         16        ROPE_END                                      2  ~13     ~14, '%3A+'
         17        ECHO                                                     ~13
   33    18        INIT_FCALL                                               'json_encode'
         19        INIT_FCALL                                               'littleendianminchunk'
         20        SEND_VAR                                                 !2
         21        SEND_VAR                                                 !3
         22        DO_FCALL                                      0  $16     
         23        SEND_VAR                                                 $16
         24        DO_ICALL                                         $17     
         25        CONCAT                                           ~18     $17, '%0A'
         26        ECHO                                                     ~18
         27      > JMP                                                      ->33
   34    28  E > > CATCH                                       last         'Exception'
   35    29    >   INIT_METHOD_CALL                                         !4, 'getMessage'
         30        DO_FCALL                                      0  $19     
         31        CONCAT                                           ~20     $19, '%0A'
         32        ECHO                                                     ~20
   30    33    >   PRE_INC                                                  !3
         34    >   IS_SMALLER_OR_EQUAL                                      !3, 13
         35      > JMPNZ                                                    ~22, ->14
   27    36    >   PRE_INC                                                  !1
         37    >   IS_SMALLER_OR_EQUAL                                      !1, !0
         38      > JMPNZ                                                    ~24, ->3
   38    39    > > RETURN                                                   1

Function littleendianminchunk:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 8
Branch analysis from position: 4
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 17
Branch analysis from position: 58
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 33
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 58, Position 2 = 17
Branch analysis from position: 58
Branch analysis from position: 17
filename:       /in/BbcfI
function name:  littleEndianMinChunk
number of ops:  62
compiled vars:  !0 = $array, !1 = $minChunkSize, !2 = $result, !3 = $count, !4 = $modulus, !5 = $expectedRemainingChunks, !6 = $sizeIncrease
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        IS_SMALLER                                               !1, 1
          3      > JMPZ                                                     ~7, ->8
    6     4    >   NEW                                              $8      'InvalidArgumentException'
          5        SEND_VAL_EX                                              '%24minChunkSize+must+be+1+or+greater'
          6        DO_FCALL                                      0          
          7      > THROW                                         0          $8
    8     8    >   COUNT                                            ~10     !0
          9        IS_SMALLER                                               ~10, !1
         10      > JMPZ                                                     ~11, ->15
    9    11    >   NEW                                              $12     'InvalidArgumentException'
         12        SEND_VAL_EX                                              '%24minChunkSize+must+not+be+less+than+the+size+of+%24array'
         13        DO_FCALL                                      0          
         14      > THROW                                         0          $12
   11    15    >   ASSIGN                                                   !2, <array>
   12    16      > JMP                                                      ->57
   13    17    >   COUNT                                            ~15     !0
         18        ASSIGN                                                   !3, ~15
   14    19        MOD                                              ~17     !3, !1
         20        ASSIGN                                                   !4, ~17
   15    21        BOOL_NOT                                         ~19     !4
         22      > JMPZ                                                     ~19, ->33
   16    23    >   INIT_FCALL                                               'array_unshift'
         24        SEND_REF                                                 !2
         25        INIT_FCALL                                               'array_chunk'
         26        SEND_VAR                                                 !0
         27        SEND_VAR                                                 !1
         28        DO_ICALL                                         $20     
         29        SEND_UNPACK                                              $20
         30        CHECK_UNDEF_ARGS                                         
         31        DO_ICALL                                                 
   17    32      > JMP                                                      ->58
   19    33    >   INIT_FCALL                                               'max'
         34        SEND_VAL                                                 1
         35        INIT_FCALL                                               'intdiv'
         36        SEND_VAR                                                 !3
         37        SEND_VAR                                                 !1
         38        DO_ICALL                                         $22     
         39        SEND_VAR                                                 $22
         40        DO_ICALL                                         $23     
         41        ASSIGN                                                   !5, $23
   20    42        INIT_FCALL                                               'ceil'
         43        DIV                                              ~25     !4, !5
         44        SEND_VAL                                                 ~25
         45        DO_ICALL                                         $26     
         46        ASSIGN                                                   !6, $26
   21    47        INIT_FCALL                                               'array_unshift'
         48        SEND_REF                                                 !2
         49        INIT_FCALL                                               'array_splice'
         50        SEND_REF                                                 !0
         51        MUL                                              ~28     !1, -1
         52        SUB                                              ~29     ~28, !6
         53        SEND_VAL                                                 ~29
         54        DO_ICALL                                         $30     
         55        SEND_VAR                                                 $30
         56        DO_ICALL                                                 
   12    57    > > JMPNZ                                                    !0, ->17
   23    58    >   VERIFY_RETURN_TYPE                                       !2
         59      > RETURN                                                   !2
   24    60*       VERIFY_RETURN_TYPE                                       
         61*     > RETURN                                                   null

End of function littleendianminchunk

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.76 ms | 1017 KiB | 22 Q