In PHP, how do I reduce objects in Symfony?

Symfony, PHP, Reduce Objects, Array Manipulation
This example demonstrates how to reduce an array of objects in Symfony using PHP's array_reduce function.
<?php // Assume we have an array of objects $users = [ (object) ['name' => 'Alice', 'age' => 30], (object) ['name' => 'Bob', 'age' => 25], (object) ['name' => 'Charlie', 'age' => 35], ]; // Reduce the users to get the total age $totalAge = array_reduce($users, function($carry, $user) { return $carry + $user->age; }, 0); echo "Total Age: " . $totalAge; ?>

Symfony PHP Reduce Objects Array Manipulation