Something like:
function getImages($dir, $num=3) {
if(!is_dir($dir))
return FALSE;
elseif($dir{(strlen($dir)-1)} != '/')
$dir .= '/';
$files = array();
foreach(glob($dir . '*') as $file) {
$files[$file] = filemtime($file);
}
arsort($files);
$files = array_slice($files, 0, $num);
return $files;
}
perhaps? Pretty straightforward... feel free to ask if you don't understand what I did.
EDIT: Code edited to return the files' modified times. The returned value of this function is either FALSE (first argument passed wasn't a directory) or an array consiting of the name of the file as a key and its value being the file's modified time. But of course, you can always see this visually using [man]print_r/man...