3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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; } ?>
based on RJTKJ
Output for 7.3.0alpha1 - 7.3.0beta1
Notice: Object of class DateTime could not be converted to number in /in/iTfGp on line 30 Notice: Object of class DateTime could not be converted to number in /in/iTfGp on line 30
Output for 5.6.0 - 5.6.30, hhvm-3.18.5 - 3.21.3, 7.0.0 - 7.2.6
Notice: Object of class DateTime could not be converted to int in /in/iTfGp on line 30 Notice: Object of class DateTime could not be converted to int in /in/iTfGp on line 30
Output for hhvm-3.22.0
Notice: Object of class DateTime could not be converted to int in /in/iTfGp on line -1 Notice: Object of class DateTime could not be converted to int in /in/iTfGp on line -1