Split an array of strings in to chunks of a maximum size
I'm attempting to ensure an array of unknown length is split in one-or-more arrays with a maximum of 20 elements. I've searched around and found several answers for similar questions based on arrays containing number sequences (or maybe I'm just missing something), but nothing for an array of strings. I've come up with a solution, but it seems a little convoluted and I feel it could probably be better. For example, take this array - And for the sake of this example, that's say I want only a maximum of two elements - So now I have an array of arrays - But... Can I achieve my goal in a more efficient way? Use a for loop, the range operator ( .. ), and the unary array construction operator ( , ): [array]$keys casts the key/value collection .Keys to a generic array (so that the index operator can be used on it). The expression $i..($i+$size-1) gives you the indexes from $i up to the index before $i+$size , i.e. the next $size elements from the array starting at pos...