Re-sorting newsfeed based on date Background: A client side I made recently has a component that is made from several (20+) rss-feeds, and the feeds are mashed into one using FreshRSS hosted on our servers. For some reason, FreshRSS sorts it in a weird order instead of the standard date latest to oldest. 

So the output looks weird with the latest post that has timestamp for today, but the second post has timestamp for last week, and the third again for today. 

So I'm capturing the output with output buffer, storing the output in an array and then storing the output array key in another array that will get sorted by date. What could I do better? 

&lt;?php

$feed = file_get_contents("secret-feed-url");

$rowArray = array();
$sortArray = array();

foreach($feed-&gt;channel-&gt;item as $item){

  ob_start();

  $media = ucfirst(str_replace([".fi", ".com", ".net"], "", parse_url($item-&gt;link, PHP_URL_HOST)));
  $date = date("d.m.Y", strtotime($item-&gt;pubDate));

  ?&gt;

  &lt;tr&gt;
    &lt;th&gt;
      &lt;a href="&lt;?php echo $item-&gt;link; ?&gt;" target="_blank" rel="noopener"&gt;
        &lt;?php echo $item-&gt;title; ?&gt;
        &lt;span class="mobile-only"&gt;
          &lt;?php echo $media . " &amp;bull; " . $date; ?&gt;
        &lt;/span&gt;
      &lt;/a&gt;
    &lt;/th&gt;
    &lt;td&gt;&lt;?php echo $media; ?&gt;&lt;/td&gt;
    &lt;td&gt;&lt;?php echo $date; ?&gt;&lt;/td&gt;
  &lt;/tr&gt;

  &lt;?php

  $row = ob_get_clean();

  $rowArray[] = $row;

  end($rowArray);
  $rowKey = key($rowArray);

  $sortArray[] = [strtotime($item-&gt;pubDate), $rowKey];

}

usort($sortArray, function($a, $b){
  return $a[0] - $b[0];
});

$sortArray = array_reverse($sortArray);

$counter = 0;

foreach($sortArray as $row){

  if($counter &gt; 10){
    break;    
  }

  echo $rowArray[$row[1]];
  $counter++;
}


I could store the "output" in a variable instead of using output buffer, but that would result in ugly code &amp; template that is pain to update compared to this. I'm not too conserned about performance, as this is cached data. 

Is there a better method for sorting this? I've done this several times on several sites, but it's usually a 1-time operation so using a framework like Symfony is a bit overkill.
usort($sortArray, function($a, $b){
  return $a[0] - $b[0];
});

$sortArray = array_reverse($sortArray);


Minor thoughts:


Instead of sorting by $a[0]-$b[0] and reversing, why not sort by $b[0]-$a[0] in the first place? However...
You could just return $b[0] &lt;=&gt; $a[0].