Jeroen Fiege’s profile

Senior web developer @humanique, founder @webcrte — webdevelopment, php, social media, blogging, games, minecraft, gadgets, apple, plex, eclipse pdt, more..

Latest Comments

1

I usually use this function (I found this functions somewhere on the internet years ago, credits go to the original author):

/*
 
 * sort a multi demensional array on a column
 
 *
 
 * @param array $array array with hash array
 
 * @param mixed $column key that you want to sort on
 
 * @param enum $order asc or desc
 
 */
 
function array_qsort2 (&$array, $column=0, $order="ASC") {
 
    $oper = ($order == "ASC")?">":"<";
 
    if(!is_array($array)) return;
 
    usort($array, create_function('$a,$b',"return (\$a['$column'] $oper \$b['$column']);")); 
 
    reset($array);
 
}

You can use it like this:

array_qsort2($users, "username", "ASC");

Posted in Sorting Multi-Dimensional Arrays in PHP.

Fri, 01 Jul 2011 at 15:06:25 GMT


About

  • Twitter: @fieg
  • Location: Rotterdam, Netherlands
  • Joined: July 2011
  • Comments: 1