I have a complex multidimensional array; the structure is like this:
[
[
'countries' => [
['country_code' => 'US', 'growth' => 3.57],
['country_code' => 'CA', 'growth' => 4.77],
['country_code' => 'TT', 'growth' => 0],
],
'group_name' => 'North America',
],
[
'countries' => [
['country_code' => 'BR', 'growth' => 2.19],
['country_code' => 'PE', 'growth' => 1.78],
['country_code' => 'UY', 'growth' => 8.83],
['country_code' => 'MX', 'growth' => 3.83],
],
'group_name' => 'South America',
],
]
I want to sort the subarrays inside each countries entry (maybe by using array_multisort
) so that they are sorted according to growth
(highest first)
So that the sorted array will be:
[
[
'countries' => [
['country_code' => 'CA', 'growth' => 4.77],
['country_code' => 'US', 'growth' => 3.57],
['country_code' => 'TT', 'growth' => 0],
],
'group_name' => 'North America',
],
[
'countries' => [
['country_code' => 'UY', 'growth' => 8.83],
['country_code' => 'MX', 'growth' => 3.83],
['country_code' => 'BR', 'growth' => 2.19],
['country_code' => 'PE', 'growth' => 1.78],
],
'group_name' => 'South America',
],
]