gilbertsavier
Joined: 26 Jun 2009 Posts: 17
|
Posted: Fri Jun 26, 2009 5:35 am Post subject: php sort using associative array |
|
|
I'm using krsort, ksort, arsort and asort in a script. Fine all goes perfectly, except that the sort field is based on file names from the directory contents, and they are (historically) ugly, as in MMDDYY, not YYYYMMDD, causing the different years to be interspersed together. I've read the man page at http://us2.php.net/manual/en/function.sort.php, and quite can't grasp what to do here. My sort code is this:
if($_GET['sort'] == 'alpha'){
if($_GET['mode'] == 'desc'){
krsort($files);
$highlight = 'alpha_desc';
} else {
ksort($files);
$highlight = 'alpha_asc';
}
} else {
if($_GET['mode'] == 'asc'){
asort($files, SORT_NUMERIC);
$highlight = 'date_asc';
} else {
arsort($files, SORT_NUMERIC);
$highlight = 'date_desc';
}
}
Thanks & Replay,
Lokananth
Live chat
http://www.mioot.com |
|