January 28, 2008

Sorting Arrays

I do always have hard times with sorting especially with arrays. And this time I want to share what I got after those sorting times. hehehe. Enjoy! :D

 

static function sortAscending(&$arr$key){ 
    $sort_col = array();  
    foreach ($arr as $sub$sort_col[] = $sub[$key]; 
    if(is_numeric($sort_col[0])) 
        array_multisort($sort_colSORT_NUMERIC$arr); 
    else if(is_string($sort_col[0])){ 
        $sort_col = array_map(’strtolower’$sort_col); 
        array_multisort($sort_colSORT_STRING$arr); 
    } 

 
static
 function sortDescending(&$arr$key){ 
    $sort_col = array(); 
    foreach ($arr as $sub$sort_col[] = $sub[$key]; 
    if(is_numeric($sort_col[0])) 
        array_multisort($sort_colSORT_NUMERICSORT_DESC$arr); 
    else if(is_string($sort_col[0])){ 
        $sort_col = array_map(’strtolower’$sort_col); 
        array_multisort($sort_colSORT_STRINGSORT_DESC$arr); 
    } 
}

For more codes, just leave a comment. :D  

2 Comments »

The URI to TrackBack this entry is: http://ienjoy.blogsome.com/2008/01/28/sorting-arrays/trackback/

  1. Lahe lge na unsa na nga language . . ?(Patrick eat’s his hair off)

    Comment by Patrick — January 29, 2008 @ 7:36 am

  2. Thanks for dropping by Pat. It’s a PHP language…hehehe…it works with sorting a list of data..

    Hope to hear you more! Thanks.

    Comment by Administrator — January 29, 2008 @ 11:16 am

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.