array sort date php code example
Example 1: php array order by date
usort($array, function($a, $b) {
return new DateTime($a['datetime']) <=> new DateTime($b['datetime']);
});
Example 2: php sort file names by date
<?php
$dirpath = getcwd();
$dirpath .= "\*.jpg";
$files = array();
$files = glob($dirpath);
usort($files, function($x, $y) {
return filemtime($x) < filemtime($y);
});
foreach($files as $item){
echo basename($item) . " => Last Modified On " . @date('F d, Y, H:i:s', filemtime($item)) . "<br/>";
}
?>