>>213108584Its actually not flanking. Any ancient army can be beaten by flanking, that's not a special weakness of the phalanx. If you pull off some crazy flank it only works against a phalanx as much as it would most other formations.
A phalanx wasn't some impervious thing. It can get worn down and punched through like anything else. Competent heavy infantry can advance through the spears and reach it. The short answer is what works against the phalanx is what generally worked against heavy infantry of the era.
If there's a particular hack to dealing with the phalanx, its what the Romans did. The Phalanx was primarily a fixing formation. You hold the enemy in place while the cavalry tries to decide the outcome of the battle. It is the phalanx's job to occupy and fix while something else delivers the killing blow.
With the Romans however, the purpose of their infantry is to kill. It is not just a fixing formation, it is meant to kill while engaged. This is why wins against roman armies tend to be less lopsided than other wins in the western world. Because roman armies tend to hurt you even if you win, cause they're trying to kill the whole time.
Recommend the Bret deveraux posts about this: https://acoup.blog/2024/01/19/collections-phalanxs-twilight-legions-triumph-part-ia-heirs-of-alexander/