PHP : Avoid duplicates in a foreach loop
<p>Hello I am looping an array like:</p>

<pre><code>Array
(
[01/04/2013 - 14:54] =&gt; Array
        (
            [0] =&gt; 13528
            [1] =&gt; status
            [2] =&gt; Waiting
            [3] =&gt; 10000
            [4] =&gt; Message to user
            [5] =&gt; Message3 to my dear user
        )

[01/04/2013 - 14:14] =&gt; Array
        (
            [0] =&gt; 13523
            [1] =&gt; status
            [2] =&gt; Waiting
            [3] =&gt; 10000
            [4] =&gt; Message to user
            [5] =&gt; Message2 to my dear user
        )

[12/20/2012 - 09:13] =&gt; Array
        (
            [0] =&gt; 13476
            [1] =&gt; status
            [2] =&gt; Waiting
            [3] =&gt; 10000
            [4] =&gt; Message to user
            [5] =&gt; Message do my dear user
       )
);
</code></pre>

<p>What I need is to display it properly avoiding duplicates:
Here is my code.</p>

<pre><code>foreach ($histories_by_date as $date =&gt; $events) {
$output .= $date;
foreach ($events as $key =&gt; $event) {
    switch ($events[$key]) {
        case 'Message from user':
            $output .= $events[$key + 1];
            break;
        case 'Message to user':
            $output .= $events[$key + 1];
            break;
       }
    }//foreach2
    }//foreach1
</code></pre>

<p>What is annoying is I get duplicates like:</p>

<pre><code>01/04/2013 - 14:54 (CET)
Message3 to my dear user

01/04/2013 - 14:14 (CET)
Message3 to my dear user
Message2 to my dear user

12/20/2012 - 09:13 (CET)
Message3 to my dear user
Message2 to my dear user
Message do my dear user
</code></pre>

<p>I only need to display as in original array.</p>
