This question is basically similar to SoulieBaby’s question here:Split MYSQL results into 4 arrays, except that I wanted to split the result to contain a specific length.
Say, I wanted the result of an array which has a length of 9 to be splitted and have the splitted array to contain 5 lengths. So first array will have 5 and second will have 4.
Is this possible?
Thanks so much for any help!
The referenced question wanted to always have 4 chunks, therefore the solution was to create chunks of size
ceil(count($array) / 5).This case is easier, the (maximum) size is constant but the number of chunks vary.
Therefore the answer is simply: