Skip to content
Advertisement

PHP sorting multidimensional array issue

this is how my array look likes:

JavaScript

I would like to sort it after alphabetical order. If I do a asort($myarray). It will sort after the first key. So I will get honda and yamaha. Which is correct, but I would like to also sort it after the type of the brand: cb-1000-r and cb-1000-a(alphabetically) and the year in a descending order. Can someone help me with this ? Thank you

[UPDATE] This is my json. you can use json_decode

JavaScript

and I would like to get this json:

JavaScript

Advertisement

Answer

You’ll need to loop through your nested arrays and sort each level of them:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement