At the risk of turning this thread into a spear vs sword debate....
The spear had economic advantages. A sword required at least two pounds a metal - and steel ain't cheap - and the skills of a sword smith and several days to make. A spear took less than a pound, could be made with cheaper metal and dozens could be cranked out by a blacksmith in a day. If you have to equip a large army, you're going to have to go with spears.
And horses...forget about it. Those things are really expensive. And, the spear, when properly used, could counter the horseman. The English attack on the Scottish schiltron is about the only thing they got right in "Braveheart".
And, knights were armed with spears too. They evolved into heavier lances, but originally they were spears.
And, the Saxon shield wall held off the Norman knight, until they broke formation.
When guns started to appear on the battlefield in the XVII century, they were very slow to reload. So, after getting off a shot or two, the gunner inserted a plug bayonet and turn their musket into....spears.
The socket bayonet allowed the gun to be fired with a fixed bayonet. But, as Joshua Lawrence Chamberlain proved at Little Round Top, the gun could still be used as a spear.