One famous example of play within a play is the "Mousetrap" scene in Shakespeare's Hamlet. In this scene, Hamlet arranges for a play to be performed that reenacts the murder of his father. The purpose of this play within a play is to catch the conscience of Claudius, the king who killed Hamlet's father. When Claudius reacts strongly to the play, Hamlet knows that he is guilty of murder.
Play within a play can also be used to create a sense of mystery or suspense. For example, in Pirandello's Six Characters in Search of an Author, a group of characters from a play appear in the middle of a rehearsal for another play. The actors and director are unsure whether the characters are real or figments of their imagination, and the play explores the nature of reality and illusion.
Play within a play can be a powerful dramatic technique that can be used to achieve a variety of effects. It can be used to provide comic relief, to comment on the main action of the play, to explore different themes or ideas, or to create a sense of mystery or suspense.