The iOS 4 firmware update includes a rotation lock feature, similar to the rotation lock switch found on the first generation iPad.
iPhone 4 ships with iOS 4 and also has this capability. To enable rotation lock and prevent the screen from automatically changing orientation when the iPhone is turned:
1. Double click the home button to bring up the multitasking bar. 2. Swipe right until the last set of icons is displayed in the multitasking bar (these will include play/pause and skip buttons for iPod or Pandora). 3. The furthest left icon looks like a circular arrow - touch this icon to enable or disable rotation lock on the iPhone. 4. A rotation lock icon will appear in the status bar next to the battery charge icon when rotation lock is enabled. This looks like a circular arrow around a padlock.
When rotation lock is enabled apps will not respond to the accelerometer sensor.
In the case you have done the iOS update, it is now on the screen that you swipe up from the bottom at the main screen. the icon to turn the rotate feature on and off is in the upper right hand side it looks like a pad lock with a circular arrow going around it. That screen that pops up has a ton of useful buttons