Clarify prevention of empty returns in array splitter
This commit is contained in:
parent
3f37dd7a9e
commit
aa7a3c5012
|
@ -770,10 +770,10 @@ final class MD_STD {
|
||||||
* Splits an lists of integers into parts of a predefined size and returns those
|
* Splits an lists of integers into parts of a predefined size and returns those
|
||||||
* as sub-lists of a superordinate list.
|
* as sub-lists of a superordinate list.
|
||||||
*
|
*
|
||||||
* @param integer[] $input Input array.
|
* @param array<int, int> $input Input array.
|
||||||
* @param positive-int $size Size of each part of the return set.
|
* @param positive-int $size Size of each part of the return set.
|
||||||
*
|
*
|
||||||
* @return array<integer[]>
|
* @return array<non-empty-array<integer>>
|
||||||
*/
|
*/
|
||||||
public static function split_int_array_into_sized_parts(array $input, int $size):array {
|
public static function split_int_array_into_sized_parts(array $input, int $size):array {
|
||||||
|
|
||||||
|
@ -786,7 +786,8 @@ final class MD_STD {
|
||||||
$max = count($input);
|
$max = count($input);
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
while ($offset < $max) {
|
while ($offset < $max) {
|
||||||
$output[] = array_slice($input, $offset, $size - 1);
|
$cur = array_slice($input, $offset, $size - 1);
|
||||||
|
if (!empty($cur)) $output[] = $cur;
|
||||||
$offset += $size;
|
$offset += $size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user