Avatar ·

How to sort a two-dimensional array by the value of one of the columns in PHP?

Hello, colleagues! I just started learning PHP and encountered a problem that seems simple, but I just can't solve it. I have a two-dimensional array that contains user data: name, age, and city. Here's what it looks like:\n\n```php\n$users = [\n ['name' => 'Ivan', 'age' => 25, 'city' => 'Moscow'],\n ['name' => 'Maria', 'age' => 30, 'city' => 'Saint Petersburg'],\n ['name' => 'Alexey', 'age' => 22, 'city' => 'Kazan'],\n ['name' => 'Elena', 'age' => 28, 'city' => 'Novosibirsk']\n];\n```\n\nI need to sort this array by age (by the 'age' key) in ascending order, so that the youngest users come first. I tried using the `sort()` function, but it completely breaks the array structure and loses the keys. I tried `ksort()` and `asort()` — they work