What are the potential pitfalls of using filemtime to sort an array of file names in PHP?

Using filemtime to sort an array of file names in PHP can lead to incorrect sorting if two files have the same modification time. To solve this issue, you can sort the files based on both modification time and file name to ensure a consistent order.

$files = glob('path/to/files/*');
usort($files, function($a, $b) {
    $mtimeA = filemtime($a);
    $mtimeB = filemtime($b);
    
    if ($mtimeA == $mtimeB) {
        return strcmp($a, $b);
    }
    
    return $mtimeA - $mtimeB;
});