In PHP, how do I split objects with built-in functions?

In PHP, you can split objects into arrays or separate properties through various built-in functions. Here’s a simple example demonstrating how to split an object into an array of properties.

PHP, Objects, Array Functions, array_chunk, array_map
This example highlights how to convert an object to an array and split it using PHP's built-in functions.
<?php class Person { public $name; public $age; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } } $person1 = new Person("Alice", 30); $person2 = new Person("Bob", 25); $people = array($person1, $person2); // Convert objects to arrays $people_array = array_map(function($obj) { return (array)$obj; }, $people); // Split the array into chunks $chunked_array = array_chunk($people_array, 1); print_r($chunked_array); ?>

PHP Objects Array Functions array_chunk array_map