If you want to sort files by last modified date, you can use
ftp_nlist($conn, '-t .');
This will not tell you what date is for each file.
If you want to also get the modified date, you can use ftp_rawlistand analyze the output. Here is a quick example that I put together:
$list = ftp_rawlist($ftp, '.');
$results = array();
foreach ($list as $line) {
list($perms, $links, $user, $group, $size, $d1, $d2, $d3, $name) =
preg_split('/\s+/', $line, 9);
$stamp = strtotime(implode(' ', array($d1, $d2, $d3)));
$results[] = array('name' => $name, 'timestamp' => $stamp);
}
usort($results, function($a, $b) { return $a['timestamp'] - $b['timestamp']; });
At this point, it $resultscontains a list sorted in ascending order of the last modified time; cancel the sort function to get the list in the last modified first format.
Note. ftp_rawlistdoes not provide exact timestamps for modification, so this code may not always work exactly. You should also make sure that the output from your FTP server is consistent with this algorithm and includes some sanity checks to ensure that this will be the case in the future.