In PHP, how do I chunk objects with Composer?

PHP, Chunking Objects, Composer, PHP Libraries, Array Manipulation
This example demonstrates how to chunk an array of objects in PHP using simple PHP functions.
<?php function chunkArray($array, $chunkSize) { $result = []; for ($i = 0; $i < count($array); $i += $chunkSize) { $result[] = array_slice($array, $i, $chunkSize); } return $result; } // Example usage $objects = [ (object) ['id' => 1, 'name' => 'Object 1'], (object) ['id' => 2, 'name' => 'Object 2'], (object) ['id' => 3, 'name' => 'Object 3'], (object) ['id' => 4, 'name' => 'Object 4'], (object) ['id' => 5, 'name' => 'Object 5'], ]; $chunked = chunkArray($objects, 2); print_r($chunked); ?>

PHP Chunking Objects Composer PHP Libraries Array Manipulation