<?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.26 ms | 402 KiB | 5 Q