The phalanx was not invented by the Greeks. The earliest example of the formation was depicted in a Sumerian stone carving from 2,500 B.C. The word phalanx was first used by Homer to describe combat in an organized battle line as distinguished from combat between individuals. Trouble is we don’t know what kind of formation Homer was describing, so we can’t know if our concept of the Phalanx dates from his time.
In the time before the Phalanx, Greek battles were disorganized affairs consisting of two opposing armies running at each other in a line. Once the Greeks perfected it, the Phalanx became the default battle formation ancient armies, until the Romans developed the maniple.