The story went, a king dreamt he was a pauper every night, and a pauper dreamt he was a king every night. The philosopher asked whether there was a difference between the two.
Pascal, in his Pensées, section 386, writes:
If we dreamt the same thing every night, it would affect us as much as the objects we see every day. And if an artisan were sure to dream every night for twelve hours' duration that he was a king, I believe he would be almost as happy as a king, who should dream every night for twelve hours on end that he was an artisan.
I imagine this is the source you are looking for.
However, while we are on the topic: Descartes, in his first Meditation, uses the example of a pauper who dreams he is a king as the canonical example of non-veridical perception. In classical Hindu philosophy, the image of a pauper dreaming he is a king and a king dreaming he is a pauper is used to question what is lost or gained upon waking (i.e., the illusory nature of the pleasure or pain experienced in the dreamstate, which can then be generalized to the illusory nature of reality). Finally, Zhuangzi famously wrote (in Chapter 2 of his eponymous work)
Once Zhuangzi dreamt he was a butterfly, a butterfly flitting and fluttering around, happy with himself and doing as he pleased. He didn't know he was Zhuangzi. Suddenly he woke up and there he was, solid and unmistakable Zhuangzi. But he didn't know if he was Zhuangzi who had dreamt he was a butterfly, or a butterfly dreaming he was Zhuangzi. Between Zhuangzi and a butterfly there must be some distinction! This is called the Transformation of Things.
There is an Indian story on similar lines. Janaka, the emperor of Videha, was having a dream every night that he was a poor farmer whose five sons were killed in a mishap and a poor farmer was having a dream that he was a king! So, Janaka poses this problem in his assembly and is actually confused about the reality of existence on the lines of - Am I real or Is this farmer real or What is real?
A young mystic, by the name of Ashtavakra(meaning - crooked in eight places), walks into his court and says - Neither the king who sees himself as the farmer nor the farmer who sees himself as the King is real! The Consciousness/Awareness overlooking these phenomena, alone is what is real. He then imparts knowledge to the bewildered king which is the famous Ashtavakra Gita.