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"; } } }
Output for git.master, git.master_jit, rfc.property-hooks
arraySize 1 chunkSize 1: [[1]] chunkSize 2: $minChunkSize must not be less than the size of $array chunkSize 3: $minChunkSize must not be less than the size of $array chunkSize 4: $minChunkSize must not be less than the size of $array chunkSize 5: $minChunkSize must not be less than the size of $array chunkSize 6: $minChunkSize must not be less than the size of $array chunkSize 7: $minChunkSize must not be less than the size of $array chunkSize 8: $minChunkSize must not be less than the size of $array chunkSize 9: $minChunkSize must not be less than the size of $array chunkSize 10: $minChunkSize must not be less than the size of $array chunkSize 11: $minChunkSize must not be less than the size of $array chunkSize 12: $minChunkSize must not be less than the size of $array chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 2 chunkSize 1: [[1],[2]] chunkSize 2: [[1,2]] chunkSize 3: $minChunkSize must not be less than the size of $array chunkSize 4: $minChunkSize must not be less than the size of $array chunkSize 5: $minChunkSize must not be less than the size of $array chunkSize 6: $minChunkSize must not be less than the size of $array chunkSize 7: $minChunkSize must not be less than the size of $array chunkSize 8: $minChunkSize must not be less than the size of $array chunkSize 9: $minChunkSize must not be less than the size of $array chunkSize 10: $minChunkSize must not be less than the size of $array chunkSize 11: $minChunkSize must not be less than the size of $array chunkSize 12: $minChunkSize must not be less than the size of $array chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 3 chunkSize 1: [[1],[2],[3]] chunkSize 2: [[1,2,3]] chunkSize 3: [[1,2,3]] chunkSize 4: $minChunkSize must not be less than the size of $array chunkSize 5: $minChunkSize must not be less than the size of $array chunkSize 6: $minChunkSize must not be less than the size of $array chunkSize 7: $minChunkSize must not be less than the size of $array chunkSize 8: $minChunkSize must not be less than the size of $array chunkSize 9: $minChunkSize must not be less than the size of $array chunkSize 10: $minChunkSize must not be less than the size of $array chunkSize 11: $minChunkSize must not be less than the size of $array chunkSize 12: $minChunkSize must not be less than the size of $array chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 4 chunkSize 1: [[1],[2],[3],[4]] chunkSize 2: [[1,2],[3,4]] chunkSize 3: [[1,2,3,4]] chunkSize 4: [[1,2,3,4]] chunkSize 5: $minChunkSize must not be less than the size of $array chunkSize 6: $minChunkSize must not be less than the size of $array chunkSize 7: $minChunkSize must not be less than the size of $array chunkSize 8: $minChunkSize must not be less than the size of $array chunkSize 9: $minChunkSize must not be less than the size of $array chunkSize 10: $minChunkSize must not be less than the size of $array chunkSize 11: $minChunkSize must not be less than the size of $array chunkSize 12: $minChunkSize must not be less than the size of $array chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 5 chunkSize 1: [[1],[2],[3],[4],[5]] chunkSize 2: [[1,2],[3,4,5]] chunkSize 3: [[1,2,3,4,5]] chunkSize 4: [[1,2,3,4,5]] chunkSize 5: [[1,2,3,4,5]] chunkSize 6: $minChunkSize must not be less than the size of $array chunkSize 7: $minChunkSize must not be less than the size of $array chunkSize 8: $minChunkSize must not be less than the size of $array chunkSize 9: $minChunkSize must not be less than the size of $array chunkSize 10: $minChunkSize must not be less than the size of $array chunkSize 11: $minChunkSize must not be less than the size of $array chunkSize 12: $minChunkSize must not be less than the size of $array chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 6 chunkSize 1: [[1],[2],[3],[4],[5],[6]] chunkSize 2: [[1,2],[3,4],[5,6]] chunkSize 3: [[1,2,3],[4,5,6]] chunkSize 4: [[1,2,3,4,5,6]] chunkSize 5: [[1,2,3,4,5,6]] chunkSize 6: [[1,2,3,4,5,6]] chunkSize 7: $minChunkSize must not be less than the size of $array chunkSize 8: $minChunkSize must not be less than the size of $array chunkSize 9: $minChunkSize must not be less than the size of $array chunkSize 10: $minChunkSize must not be less than the size of $array chunkSize 11: $minChunkSize must not be less than the size of $array chunkSize 12: $minChunkSize must not be less than the size of $array chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 7 chunkSize 1: [[1],[2],[3],[4],[5],[6],[7]] chunkSize 2: [[1,2],[3,4],[5,6,7]] chunkSize 3: [[1,2,3],[4,5,6,7]] chunkSize 4: [[1,2,3,4,5,6,7]] chunkSize 5: [[1,2,3,4,5,6,7]] chunkSize 6: [[1,2,3,4,5,6,7]] chunkSize 7: [[1,2,3,4,5,6,7]] chunkSize 8: $minChunkSize must not be less than the size of $array chunkSize 9: $minChunkSize must not be less than the size of $array chunkSize 10: $minChunkSize must not be less than the size of $array chunkSize 11: $minChunkSize must not be less than the size of $array chunkSize 12: $minChunkSize must not be less than the size of $array chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 8 chunkSize 1: [[1],[2],[3],[4],[5],[6],[7],[8]] chunkSize 2: [[1,2],[3,4],[5,6],[7,8]] chunkSize 3: [[1,2,3,4],[5,6,7,8]] chunkSize 4: [[1,2,3,4],[5,6,7,8]] chunkSize 5: [[1,2,3,4,5,6,7,8]] chunkSize 6: [[1,2,3,4,5,6,7,8]] chunkSize 7: [[1,2,3,4,5,6,7,8]] chunkSize 8: [[1,2,3,4,5,6,7,8]] chunkSize 9: $minChunkSize must not be less than the size of $array chunkSize 10: $minChunkSize must not be less than the size of $array chunkSize 11: $minChunkSize must not be less than the size of $array chunkSize 12: $minChunkSize must not be less than the size of $array chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 9 chunkSize 1: [[1],[2],[3],[4],[5],[6],[7],[8],[9]] chunkSize 2: [[1,2],[3,4],[5,6],[7,8,9]] chunkSize 3: [[1,2,3],[4,5,6],[7,8,9]] chunkSize 4: [[1,2,3,4],[5,6,7,8,9]] chunkSize 5: [[1,2,3,4,5,6,7,8,9]] chunkSize 6: [[1,2,3,4,5,6,7,8,9]] chunkSize 7: [[1,2,3,4,5,6,7,8,9]] chunkSize 8: [[1,2,3,4,5,6,7,8,9]] chunkSize 9: [[1,2,3,4,5,6,7,8,9]] chunkSize 10: $minChunkSize must not be less than the size of $array chunkSize 11: $minChunkSize must not be less than the size of $array chunkSize 12: $minChunkSize must not be less than the size of $array chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 10 chunkSize 1: [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10]] chunkSize 2: [[1,2],[3,4],[5,6],[7,8],[9,10]] chunkSize 3: [[1,2,3],[4,5,6],[7,8,9,10]] chunkSize 4: [[1,2,3,4,5],[6,7,8,9,10]] chunkSize 5: [[1,2,3,4,5],[6,7,8,9,10]] chunkSize 6: [[1,2,3,4,5,6,7,8,9,10]] chunkSize 7: [[1,2,3,4,5,6,7,8,9,10]] chunkSize 8: [[1,2,3,4,5,6,7,8,9,10]] chunkSize 9: [[1,2,3,4,5,6,7,8,9,10]] chunkSize 10: [[1,2,3,4,5,6,7,8,9,10]] chunkSize 11: $minChunkSize must not be less than the size of $array chunkSize 12: $minChunkSize must not be less than the size of $array chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 11 chunkSize 1: [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11]] chunkSize 2: [[1,2],[3,4],[5,6],[7,8],[9,10,11]] chunkSize 3: [[1,2,3],[4,5,6,7],[8,9,10,11]] chunkSize 4: [[1,2,3,4,5],[6,7,8,9,10,11]] chunkSize 5: [[1,2,3,4,5],[6,7,8,9,10,11]] chunkSize 6: [[1,2,3,4,5,6,7,8,9,10,11]] chunkSize 7: [[1,2,3,4,5,6,7,8,9,10,11]] chunkSize 8: [[1,2,3,4,5,6,7,8,9,10,11]] chunkSize 9: [[1,2,3,4,5,6,7,8,9,10,11]] chunkSize 10: [[1,2,3,4,5,6,7,8,9,10,11]] chunkSize 11: [[1,2,3,4,5,6,7,8,9,10,11]] chunkSize 12: $minChunkSize must not be less than the size of $array chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 12 chunkSize 1: [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12]] chunkSize 2: [[1,2],[3,4],[5,6],[7,8],[9,10],[11,12]] chunkSize 3: [[1,2,3],[4,5,6],[7,8,9],[10,11,12]] chunkSize 4: [[1,2,3,4],[5,6,7,8],[9,10,11,12]] chunkSize 5: [[1,2,3,4,5,6],[7,8,9,10,11,12]] chunkSize 6: [[1,2,3,4,5,6],[7,8,9,10,11,12]] chunkSize 7: [[1,2,3,4,5,6,7,8,9,10,11,12]] chunkSize 8: [[1,2,3,4,5,6,7,8,9,10,11,12]] chunkSize 9: [[1,2,3,4,5,6,7,8,9,10,11,12]] chunkSize 10: [[1,2,3,4,5,6,7,8,9,10,11,12]] chunkSize 11: [[1,2,3,4,5,6,7,8,9,10,11,12]] chunkSize 12: [[1,2,3,4,5,6,7,8,9,10,11,12]] chunkSize 13: $minChunkSize must not be less than the size of $array arraySize 13 chunkSize 1: [[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13]] chunkSize 2: [[1,2],[3,4],[5,6],[7,8],[9,10],[11,12,13]] chunkSize 3: [[1,2,3],[4,5,6],[7,8,9],[10,11,12,13]] chunkSize 4: [[1,2,3,4],[5,6,7,8],[9,10,11,12,13]] chunkSize 5: [[1,2,3,4,5,6],[7,8,9,10,11,12,13]] chunkSize 6: [[1,2,3,4,5,6],[7,8,9,10,11,12,13]] chunkSize 7: [[1,2,3,4,5,6,7,8,9,10,11,12,13]] chunkSize 8: [[1,2,3,4,5,6,7,8,9,10,11,12,13]] chunkSize 9: [[1,2,3,4,5,6,7,8,9,10,11,12,13]] chunkSize 10: [[1,2,3,4,5,6,7,8,9,10,11,12,13]] chunkSize 11: [[1,2,3,4,5,6,7,8,9,10,11,12,13]] chunkSize 12: [[1,2,3,4,5,6,7,8,9,10,11,12,13]] chunkSize 13: [[1,2,3,4,5,6,7,8,9,10,11,12,13]]

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
54.9 ms | 437 KiB | 5 Q