Reply to topic
php sort using associative array
gilbertsavier


Joined: 25 Jun 2009
Posts: 9
Reply with quote
Hi,
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.

Code:
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';
    }
}
nathacof
Forum Admin

Joined: 24 Oct 2006
Posts: 192
Location: Dover, DE
Reply with quote
Perhaps it's time to correct the poor naming convention? You could write a PHP script to move the directories such that they have proper names. That way you won't have to code something to compensate for something that you know isn't the best implementation.
php sort using associative array
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic