How to sort a two-dimensional array by the value of one of the columns in PHP?
Hello everyone! I'm a beginner in PHP and encountered a task that stumped me. I have a two-dimensional array (multidimensional) that contains user data. Here's an example:
```php
$users = [
['name' => 'Ivan', 'age' => 25, 'salary' => 50000],
['name' => 'Maria', 'age' => 30, 'salary' => 60000],
['name' => 'Petr', 'age' => 22, 'salary' => 45000],
['name' => 'Anna', 'age' => 28, 'salary' => 55000]
];
```
I need to sort this array by age (`age`) in ascending order, so that the youngest users come first. I tried using `sort()`, `asort()`, and `ksort()`, but they only work with one-dimensional arrays and simply shuffle rows or keys without sorting by the internal field.
I also read about `array_multisort()`, but didn't understand how
No answers yet.
Log in to leave an answer