One theory I have heard about is that a hiccup is left over from our amphibian ancestors. Frogs, toads and newts mainly breathe through their skin (which is why it has to stay damp) but they can also breathe air by swallowing it and gulping it down. This is the basis of a hiccup – it is an involuntary intake of air and that causes the vocal cords to close suddenly as the air rushes through them. Only mammals have the hiccup reflex and it is commonest in very young children getting less frequent as we get older.
Things which cause your stomach to swell or which irritate your stomach cause the phrenic nerve to activate the diaphragm which is the skin over the bottom of our chest which we use as part of the way we breathe. Usually hiccups stop on their own and there are all sorts of “cures” such as giving the person a fright, putting something cold down their neck or drinking a glass of water upside down. Sometimes they can go on for months and this seriously weakens the sufferer to the point where they might die and surgery is necessary to cut the phrenic nerve.
I find holding my breath for about 15 seconds gets rid of my hiccups. I hope this helps.