iCloud backs up photos and videos stored on your iPhone. If you use iCloud Photo Library (Beta), they are not included, because they are already saved to iCloud. In any case, you can backup to iCloud, then erase the iPhone without worrying about your pictures.
Hope that helps.