Using uksort
:
uksort($array, function($a, $b) { return count($b) - count($a); });
Using array_multisort
:
array_multisort(array_map('count', $array), SORT_DESC, $array);
With PHP < 5.3:
function sort_cb($a, $b) {
return count($b) - count($a);
}
uksort($array, 'sort_cb');
More Related Contents:
- How to Sort a Multi-dimensional Array by Value
- How to sort an array of associative arrays by value of a given key in PHP?
- Sort multidimensional array by multiple columns
- Sorting a php array of arrays by custom order
- Sorting a multidimensional array in PHP? [duplicate]
- How do I sort a multidimensional array by one of the fields of the inner array in PHP? [duplicate]
- Sort array of objects by one property
- How to sort a multidimensional array by a certain key?
- Sort multidimensional array by date column, then use other column values if dates are the same
- Recursively sort keys of a multidimensional array
- Sort an array of associative arrays by column value
- how to sort a multidemensional array by an inner key
- Sorting an associative array in PHP [duplicate]
- Preserve key order (stable sort) when sorting with PHP’s uasort
- String with array structure to Array [duplicate]
- Group array by subarray values
- Recursively remove empty elements and subarrays from a multi-dimensional array
- PHP remove duplicate values from multidimensional array
- Checking if array is multidimensional or not?
- scandir() to sort by date modified
- Sort Object in PHP
- How to check if a specific value exists at a specific key in any subarray of a multidimensional array?
- Group 2d array data using column value to create a 3d array
- Get array’s key recursively and create underscore separated string
- php multidimensional array get values
- Sort array by value alphabetically php
- How to have a stable sort in PHP with arsort()?
- Set value of single object in multidimensional array in twig template
- How do I move an array element with a known key to the end of an array in PHP?
- Recreate original PHP array from print_r output [duplicate]