Did Prophet Muhammad quote what is mentioned in the Qur’an from the previous civilizations?

Some of the sciences of the ancient civilizations were sound, whereas many of them were only myths and superstitions. How was an illiterate Prophet, who grew up in a barren desert, able to copy from these civilizations the sound knowledge only leaving out the myths?

PDF