Answers for "array sort date php"

PHP
2

php array order by date

usort($array, function($a, $b) {
  return new DateTime($a['datetime']) <=> new DateTime($b['datetime']);
});
Posted by: Guest on January-09-2020
1

php sort file names by date

<?php
// get current directory path
$dirpath = getcwd();
// set file pattern
$dirpath .= "\*.jpg";
// copy filenames to array
$files = array();
$files = glob($dirpath);

// sort files by last modified date
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/>";
}
?>
Posted by: Guest on August-27-2020

Browse Popular Code Answers by Language