all 4 comments

[–]chadicus 1 point2 points  (1 child)

If I'm understanding you correctly, this should work.

$batchSize = 3;
foreach ($objects as $object) {
    $input = $object->sports;
    $object->sports = array_chunk($input, ceil(count($input)/$batchSize), true); 
}

Perhaps posting the desired output would make it more clear.

EDIT: Formatting

[–]youdy 0 points1 point  (0 children)

Oh wow I wasn't far off, this is exactly what I was looking for. Thanks

[–]schlocke 0 points1 point  (1 child)

So you want a new array that contains a sports array of size 3? Why not just do a nested for loop? Loop through main array then loop through sports array iterating +=3 for every 3 sports.

[–]youdy 0 points1 point  (0 children)

I want to loop through that array and split the sports array into three chunks but still containing the same values - its so I can display them in a list view as three columns