In PHP you can do this to order an array of strings by their size:
usort($parts, function($a, $b) {
return strlen($b) - strlen($a);
});
How do I order an array of strings by size but if two strings are the same size, order them by their index in the original array.
eg:
I a o delicious cake
becomes:
delicious cake I a o
At the moment with my current code it becomes:
delicious cake o a i