Why does my sound stop working on iPhone 4?

My iPhone sound will go through periods where most of the sound will stop working for a few hours and then it will just randomly start working again. I've checked the settings over again and it's not the silent switch, also I've tried turning it off and on but it nothing works. When the sound goes out its pretty much everything except the ringer but the alert tones go out, videos in safari, keyboard clicks, lock sounds, and charging sounds all go silent. It's really annoying does anyone know what is causing this and how I can fix it?

Your speaker may have a shortage where the wire is frayed a bit. Take it to the apple store I think they can replace it once for free

This is really easy you can just get it fixed by going to the apple store and telling them to fix it i'm pretty sure they will do it for free or just maybe take about 2-5 pound.

Because iPhone is not value for money