iPhone audio gets confused when Earbuds are uplugged

Sometimes when you unplug a headset from the iPhone it gets lost and confused and you can neither hear nor talk using the internal speaker or microphone. Interestingly – it works as a speakerphone but not as a regular phone.
Quick tip: If you answer a call and put it to your ear and cannot hear – don’t panic – switch to speakerphone this will work.
Solving the problem: Solving the problem is simple – just insert and remove your headphones three times and voila – it works!
References:
http://discussions.apple.com/thread.jspa?messageID=6830349