Consider this simple example array:
$letters = [
['a', 'c', 'f'],
['c', 'f'],
['b', 'd', 'x', 'c', 'f'],
['f']
];
I need to order the array in descending order by number of letters (or anyway, by the number of elements in each array item:
'b', 'd', 'x', 'c', 'f'
'a', 'c', 'f'
'c', 'f'
'f'
This should give you the result you are looking for:
$letters = [
['a', 'c', 'f'],
['c', 'f'],
['b', 'd', 'x', 'c', 'f'],
['f']
];
usort($letters, 'order');
function order($a, $b){
return (count($a) < count($b) ? 1 : -1);
}
var_dump($letters);