- To a child with a hammer everything looks like a nail.
- If the only tool you have is a hammer, you treat everything like a nail.
The first variant is easy to understand in that it says that if you give a hammer to someone very young they will go around trying that hammer out on everything until there's very little left to hammer. As I said, before there's a slightly gleefully destructive bent to it.
I've never seen a particularly fluid version of the second variant, though. I've tried to rewrite it as "When the only tool you've got is a hammer, every problem tends to look like a nail" which I think gets as close to what I think the phrase means without being overly pedantic about it. It's saying that if you have only one problem solving tool that you try to solve all your problems with that tool, that sometimes you have to think outside of the toolbox.
The other variants (and they maybe more widespread than mine, it's just that I think the above two are the only ones that make much sense) are mostly of the form "He that is good with a hammer tends to think everything is a nail" which gets someway to expressing both ideas above before falling between the two of them. Sometimes altering the saying garbles its meaning totally.
This kind of leads me on to another rant. We all know the Sean Connery story by now, I get a couple of people at this site a month looking for it. Again, there are variants. The year changes, mostly 1963 or 1964, it's not particularly important—I use 1964 by preference—1976 and 1989 feel wrong for all sorts of reasons but they're out there. And the order of the first two sentences are negotiable "1963. Petula Clark" or "Petula Clark. 1964", you know, whatever. The anecdote, though, is built on the old Comedy rule of three. It's a three part list that builds to its punchline, which is why 'Petula Clark, up the arse, 1964' annoys me enough that I felt the need to mention it. The bloke telling the story claims to have got "the desired laughter", but I doubt it. It's just wrong.