'Alice', 'age' => 25]; $person2 = (object)['city' => 'New York']; $person3 = (object)['name' => 'Bob', 'age' => 30, 'city' => 'Los Angeles']; $merged = (object) array_merge((array)$person1, (array)$person2, (array)$person3); // Alternative syntax: // $merged = (object) array_merge(get_object_vars($person1), get_object_vars($person2), get_object_vars($person3)); var_dump($merged); ?>
color = $color; } } class Circle extends Shape { public $radius; public function __construct($color, $radius) { parent::__construct($color); $this->radius = $radius; } } $circle1 = new Circle('red', 5); $circle2 = new Circle('green', 7); $merged = (object) array_merge((array)$circle1, (array)$circle2); var_dump($merged); ?>This code merges the properties of two Circle objects into a single object. The resulting object contains the color and radius properties. This function is part of the PHP core, so you don't need to install any external library.