Avatar ·

How to sort an array of objects by one property in PHP?

Hello everyone! I'm a beginner PHP developer and I've encountered a problem with sorting an array of objects. I have an array that contains objects of the `User` class. Each object has `name` and `age` properties. Here's what my code looks like: ```php class User { public $name; public $age; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } } $users = [ new User('Ivan', 25), new User('Maria', 30), new User('Petr', 20), new User('Anna', 28) ]; ``` I need to sort this array by the `age` property in ascending order, so that the output is: Petr (20), Ivan (25), Anna (28), Maria (30). I tried using the `sort()` function, but it doesn't work with objects. I attempted to use `usor