The way I accomplished this with my iPod Touch, on my MacBook, was to plug it in and wait for the iPod to sync (or you can cancel it). Then when it was done, in the menu at the top of the screen (menu bar, as some call it), choose file and then in the drop down menu, there is an option to transfer purchases from iPod. Should be the same with the iPhone.
Itunes then performs a sync of apps from the iPod to the computer. Everything should be the same for the iPhone, as they interface the same way with iTunes.
As for a PC, I am not sure at this moment if the option is in the same location as on the Mac, but it should be.