title: Merge array elements within time range - how?
body: <p>I have an array that contain user's activities on the website. It contains activities such as writing comments, news and groups. If two comments (or more) from different users have been written within an hour, I would like to gather those two arrays into one: User and 2 more commented on X. The code I have so far looks like this:</p>
  
  <pre><code>&lt;?php
  
  $output = array();
  $output[] = array('userID' =&gt;  12, 'txt' =&gt; sprintf('%s commented in %s', 'User1', 'Event'), 'date' =&gt; 1393080072);
  $output[] = array('userID' =&gt;  13, 'txt' =&gt; sprintf('%s commented in %s', 'User2', 'Event'), 'date' =&gt; 1393080076);
  $output[] = array('userID' =&gt;  13, 'txt' =&gt; sprintf('%s created the news %s', 'User2', 'RANDOMNEWS'), 'date' =&gt; 1393080080);
  $output[] = array('userID' =&gt;  14, 'txt' =&gt; sprintf('%s commented in %s', 'User3', 'Event'), 'date' =&gt; 1393080088);
  
  $date = array();
  foreach($output as $k =&gt; $d) {
    $date[$k] = $d['date'];
  }
  
  array_multisort($date, SORT_DESC, $output);
  
  print_r($output);
  
  ?&gt;
  </code></pre>
  
  <p>So far the code above sorts the arrays by date (DESC). Desired result: one array: %s and 2 more commented in... and the other arrays removed from output. So by taking the latest comment and checking the date from the rest of the comments, it should be possible to handle this. I simply need some suggestions.</p>
  
  <p>Thanks in advance</p>