If you need to use the uid instead of msgno use
imap_clearflag_full($stream, implode(',', $flags), '\\DELETED', ST_UID);(PHP 4, PHP 5, PHP 7, PHP 8)
imap_undelete — Unmark the message which is marked deleted
Removes the deletion flag for a specified message, which is set by imap_delete() or imap_mail_move().
imapAn IMAP\Connection instance.
message_nums
       A string representing one or more messages in IMAP4-style sequence format
       ("n", "n:m", or combination of these
       delimited by commas).
      
flags
   Always returns true.
  
| Versione | Descrizione | 
|---|---|
| 8.1.0 | The imapparameter expects an IMAP\Connection
  instance now; previously, a validimapresource was expected. | 
If you need to use the uid instead of msgno use
imap_clearflag_full($stream, implode(',', $flags), '\\DELETED', ST_UID);The imap_delete function allows the option to use a UID for the message number but the imap_undelete function does not.