i haven't had it happen on iphone but occurs every once in awhile on ipad, though i have no idea why. here's my fix:
try plugging and unplugging headphones. for some reason, every so often it thinks there are headphones attached and won't play any sound. when that happens, i lock the screen, plug headphones, turn back on, and unplug. voila! sound works again.
Already tried that unfortunately, fixing nothing. I've taken a flashlight to the jack to ensure no debris is there, sure enough there was none. Also tried using a hairdryer to dry it out incase of water damage, again no result.