diff --git a/src/MD_STD.php b/src/MD_STD.php index afee1d4..1c3f9c8 100644 --- a/src/MD_STD.php +++ b/src/MD_STD.php @@ -773,7 +773,7 @@ final class MD_STD { * @param array $input Input array. * @param positive-int $size Size of each part of the return set. * - * @return array> + * @return array> */ public static function split_int_array_into_sized_parts(array $input, int $size):array { @@ -788,7 +788,36 @@ final class MD_STD { while ($offset < $max) { $cur = array_slice($input, $offset, $size - 1); if (!empty($cur)) $output[] = $cur; - $offset += $size; + $offset += $size - 1; + } + + return $output; + + } + + /** + * Splits an lists of strings into parts of a predefined size and returns those + * as sub-lists of a superordinate list. + * + * @param array $input Input array. + * @param positive-int $size Size of each part of the return set. + * + * @return array> + */ + public static function split_string_array_into_sized_parts(array $input, int $size):array { + + /* + if ($size < 1) throw new Exception("Size of the target array must be a positive integer"); + */ + + $output = []; + + $max = count($input); + $offset = 0; + while ($offset < $max) { + $cur = array_slice($input, $offset, $size - 1); + if (!empty($cur)) $output[] = $cur; + $offset += $size - 1; } return $output;