Time flies like an arrow; fruit flies like a banana

"Time flies like an arrow; fruit flies like a banana" is a humorous saying that is used in linguistics as an example of a garden path sentence or syntactic ambiguity, and in word play as an example of punning, double entendre, and antanaclasis.
The point of the example is that the correct parsing of the second sentence, "fruit flies like a banana", is not the one that the reader starts to build, by assuming that "fruit" is a noun (the subject), "flies" is the main verb, and "like" as a preposition. The reader only discovers that the parsing is incorrect when it gets to the "banana". At that point, in order to make sense of the sentence, the reader is forced to reparse it, with "fruit flies" as the subject and "like" as the main verb.
The first sentence predisposes the reader towards the incorrect parsing of the second. After reparsing the second, it becomes clear that the first sentence could be re-parsed in the same way.
The sentence "time flies like an arrow" is in fact often used to illustrate syntactic ambiguity.
Modern English speakers understand the sentence to unambiguously mean "Time passes fast, as fast as an arrow travels". But the sentence is syntactically ambiguous and alternatively could be interpreted as meaning, for example:
In addition, the sentence contains semantic ambiguity. For instance, the noun phrase "Time flies" could refer to all time flies or particular time flies, and "an arrow" to all arrows, a particular arrow, or different arrows for different flies; compare "Fruit flies like a banana", "Fruit flies ate a banana", "Fruit flies live on a banana". Moreover, "Time flies" could refer to "flies of the Time magazine", or "flies of the Pink Floyd song Time". Indeed, a copy of the magazine or the song could also be the subject doing the flying. Furthermore, "like" as a verb could either signify general enjoyment, or the usage of a like button.
The expression is based on the proverb: "Time flies", a translation of the Latin Tempus fugit, where "fly" is to be taken in the sense of flee.
An early example of a pun with the expression "Time flies" may be found in a 1930 issue of Boys' Life:
Anthony Oettinger gives "fruit flies like bananas" as contrasted with "time flies like an arrow" as an example of the difficulty of handling ambiguous syntactic structures as early as 1963, although his formal publications with Susumu Kuno do not use that example. This is quoted by later authors.
A fuller exposition with the banana example appeared in a 1966 article by Oettinger.
This article prompted the following response in a letter:
The verse is popular as a specimen of didactic humor trading on syntactic ambiguity. Like the poem "The Chaos" by Gerard Nolst Trenité, its themes are popular among practitioners and students in fields such as natural language processing and linguistics.
The saying is sometimes attributed to Groucho Marx, but according to The Yale Book of Quotations, there is no reason to believe Marx actually said this. Instead, it traces the Marx attribution to a post from July 9, 1982 on the Usenet group net.jokes; however, the closest match in the Google Groups archives is really dated to September 8, and does not mention Marx.
The saying is used as a linguistic example of antanaclasis, the stylistic trope of repeating a single word, but with a different meaning each time.
It is also used as an example of punning. The wordplay is based on the distinct meanings of the two occurrences of the word flies (the verb "travel through the air" and the noun for certain insects), and of the word like (the preposition "similarly to" and the verb "enjoy"). For example, the second clause can be read as "fruit travels through the air similar to a banana" or as "certain insects enjoy a banana".
This is an example of a garden-path sentence, a phrase that the reader or listener normally begins to parse according to one grammatical structure, and is then forced to back up and reparse when the sentence ends in an unexpected way.