Skip to content
Advertisement

Sorting an array of arrays by the child array’s length?

What’s the best way in PHP to sort an array of arrays based on array length?

e.g.

JavaScript

Advertisement

Answer

This will work:

JavaScript

Note that this function will preserve the numerical keys. If you want to reset the keys, wrap it in a call to array_values().

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