I have an array such as:
$array = [
'DEF' => [
['type' => 1, 'id' => 1212, 'name' => 'Jane Doe', 'current' => 1],
['type' => 1, 'id' => 3123121, 'name' => 'Door', 'current' => null],
],
'ABC' => [
['type' => 1, 'id' => 1234, 'name' => 'John Doe', 'current' => null],
],
'WW' => [
['type' => 1, 'id' => 1212, 'name' => 'Jane Doe', 'current' => 1],
['type' => 1, 'id' => 3123121, 'name' => 'Door', 'current' => null],
['type' => 1, 'id' => 64646, 'name' => 'Floor', 'current' => null],
]
];
And I want to sort this array by number ( count() ) of inner-array items descending (i.e. most items first), so I will have this array:
[
'WW' => [
['type' => 1, 'id' => 1212, 'name' => 'Jane Doe', 'current' => 1],
['type' => 1, 'id' => 3123121, 'name' => 'Door', 'current' => null],
['type' => 1, 'id' => 64646, 'name' => 'Floor', 'current' => null],
],
'DEF' => [
['type' => 1, 'id' => 1212, 'name' => 'Jane Doe', 'current' => 1],
['type' => 1, 'id' => 3123121, 'name' => 'Door', 'current' => null],
],
'ABC' => [
['type' => 1, 'id' => 1234, 'name' => 'John Doe', 'current' => null],
]
];
Can anyone suggest an efficient way to do so? Thanks.
usort
php.net/manual/en/function.usort.php ? – Stannite