How can you prevent the same smiley from being displayed multiple times in a shoutbox using PHP?

To prevent the same smiley from being displayed multiple times in a shoutbox using PHP, you can keep track of the smileys that have already been displayed. Before displaying a smiley, you can check if it has already been displayed and if so, skip displaying it again.

<?php
// Sample array of smileys
$smileys = ['😊', '😂', '😍', '😊', '😂'];

$displayedSmileys = [];

foreach ($smileys as $smiley) {
    if (!in_array($smiley, $displayedSmileys)) {
        echo $smiley . ' ';
        $displayedSmileys[] = $smiley;
    }
}
?>