Issue
lets say there is an array like this [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]. How can add every 7 values into a new array that looks like this [[0,1,2,3,4,5,6],[7,8,9,10,11,12],[13,14,15,16]
Solution
If the arrays will be equally sized (your example has 7 values in the first array and six in the second - not sure if it's a typo or not) then you can do this:
$array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
$chunkedArrays = array_chunk($array, 7);
print_r($chunkedArrays);
array_chunk documentation here
Answered By - martincarlin87
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.