3v4l.org

run code in 300+ PHP versions simultaneously
<?php $newsArray = array(); $item_title = 'Hello World'; $media = 'Prothom Alo'; $pubDate = 'Sun, 18 Mar 2018 05:51:28 GMT'; //echo (new DateTime('Sun, 18 Mar 2018 05:51:28 GMT'))->format('l, d F Y'); $newsArray[0] = array( 'title' => (string)$item_title, 'media' => (string)$media, 'pubdate' => new DateTime($pubDate) ); $item_title = 'Hello World 2'; $media = 'Prothom Alo 2'; $pubDate = 'Sun, 19 Mar 2018 05:51:28 GMT'; $newsArray[1] = array( 'title' => (string)$item_title, 'media' => (string)$media, 'pubdate' => new DateTime($pubDate) ); usort($newsArray,'date_compare'); function date_compare($a, $b) { $t1 = $a['pubdate']; $t2 = $b['pubdate']; return $t1 - $t2; } ?>

preferences:
52.5 ms | 402 KiB | 5 Q