Sorting an array of objects by one property in PHP
Hello everyone! I'm a beginner in PHP and I've encountered a problem when sorting an array of objects. I have an array that contains objects of the `User` class. Each object has properties `name`, `age`, and `score`. I need to sort this array by the `age` property in ascending order, but I can't figure out how to do it correctly.
Here's an example of my code:
```php
class User {
public $name;
public $age;
public $score;
public function __construct($name, $age, $score) {
$this->name = $name;
$this->age = $age;
$this->score = $score;
}
}
$users = [
new User('Alice', 25, 90),
new User('Bob', 30, 85),
new User('Charlie', 22, 95),
new User('Diana', 28, 88)
];
// Trying to sort, but I don't know which function