We can sort an array by using some non-trivial criteria in PHP by using a user defined comparison function. In the function usort we can use our own sort criteria by using one function.
Here is the user defined function has to have some matching requirements. One is it has to accept two variables. It should return either 0,less than 0 or greater than 0 based on the matching where first element is less than , equal to or greater than second element.
After the sorting the small word ( by length ) will be at the first and the longest word will to the end.
This usort function does not retain the associated index or the key of the elements of the array.