Google! There's always someone out there smarter than you who will have written a better function/code that you could have done or approached it from a different perspective.
Plus if you google you invariably end up learning new stuff and you might realise the function you were trying to remember has now been deprecated and you get a nice shiny new one in its place, or you might find the function that would solve all your problems is in the latest release of your language and so it's time to upgrade.
Depending on the problem, you may only get part of your solution from googling but it might be enough to send you on the right path.
If you're a good developer then you'll understand how someone has arrived at a solution or you'll strive to get some understanding of it. You'll also be able to weed out the bad solutions.
You'll also finish your code quicker than struggling for five hours and make yourself look like a genius to your boss :)