list files from folder, only one for each date

Posted on 16th Feb 2014 by admin

I have many files in a folder and wish to only list one of each date

these are the file names.
date format (dd/mm/yyy)

abc - 12-01-2009 - something.pdf
abc - 12-01-2009 - something else.pdf
abc - 12-01-2009 - another title.pdf
abc - 24-05-2009 - some other text
abc - 24-05-2009 - yet more files
abc - 24-05-2009 - yet another title.pdf

if i had these files then i would like the results to be

12-01-2009
24-05-2009

in an array


at present i have this script..

Code: $files = glob('agendas/*.pdf');
$sortfile = array();
foreach($files as $file){
//Extract date
if (preg_match('/(d+)-(d+)-(d+)[^.]*?.pdf/', $file, $reg)) {
//if (preg_match('/(d+)-(d+)-(d+)-Agenda Item (d+)[^.]*?.pdf/', $file, $reg)) {
//add date to array (file as key)
$sortfile[$file] = mktime(0,0,0,$reg[2],$reg[1],$reg[3]);
}
}

this only gets the files but i would like to have these files sorted and have only one of each date

how would this be done.

Other forums