title: avoid duplicates in flash based messaging
body: <p>I am using a php session-based flash messenger <a href="http://mikeeverhart.net/php/session-based-flash-messages/" rel="nofollow">available</a> here. The issue is sometimes I get multiple messages of the same type when I generate errors, display messages, so on and so fourth. This is mostly due to some AJAX issues. Assuming that I wanted to only apply a fix in the display code here:</p>
  
  <pre><code>public function display($type = 'all', $print = true)
  {
      $messages = '';
      $data = '';
      if (!isset($_SESSION['flash_messages'])) {
          return false;
      }
      // print a certain type of message?
      if (in_array($type, $this-&gt;msgTypes)) {
          foreach ($_SESSION['flash_messages'][$type] as $msg) {
              $messages .= $this-&gt;msgBefore . $msg . $this-&gt;msgAfter;
          }
          $data .= sprintf($this-&gt;msgWrapper, $this-&gt;msgClass, $this-&gt;msgClassPrepend.'-'.$type, str_replace('messages', 'autoclose',$this-&gt;msgClassPrepend.'-'.$type), $messages);
          // clear the viewed messages
          $this-&gt;clear($type);
      // print ALL queued messages
      } elseif ($type == 'all') {
          $counter = 1;
          foreach ($_SESSION['flash_messages'] as $type =&gt; $msgArray) {
              $count = $counter++;
              $messages = '';
              foreach ($msgArray as $msg) {
                  $messages .= $this-&gt;msgBefore . $msg . $this-&gt;msgAfter;
              }
              $data .= sprintf($this-&gt;msgWrapper, $this-&gt;msgClass, $this-&gt;msgClassPrepend.'-'.$type, str_replace('messages', 'autoclose', $this-&gt;msgClassPrepend.'-'.$type), $messages);
          }
          // clear ALL of the messages
          $this-&gt;clear();
          // invalid message type?
      } else {
          return false;
      }
      // print everything to the screen or return the data
      if ($print) {
          echo $data;
      } else {
          return $data;
      }
  }
  </code></pre>
  
  <p>How would I make it so that duplicate messages are detected on a 1 for 1 basis. So if the message is "Hello" and "Hello" and "Hello." I can remove one of the first two, and keep the later as it is a different message so to speak. All the workarounds I can think of would be overly complex, and I was wondering if anyone could think of a simple solution.</p>
  
  <p>Additional info: <code>display</code> is encased in <code>class Messages</code> and a new message is created with         </p>
  
  <pre><code>$msg = new Messages();
  $msg-&gt;add('e', 'Some error here.');
  </code></pre>