Answer:
Matthew 7:12 "So in everything, do to others what you would have them do to you, for this sums up the Law and the Prophets."
Luke 6:31 "Do to others as you would have them do to you."
(verses are quoted in the New International Version of the Bible)
The reason that it appears so similarly in each of these different books is that Matthew, Mark, and Luke are referred to as the Synoptic Gospels--that is, they relate many of the same events and record many of the same teachings of Jesus; however, they were written from different perspectives and for different intended audiences. So some of the content is repeated between these books.