Remove unnecessary (static) variable $already_sorted.
Refactor one-time do-while(0) loop and single (!) break check.