Re: sorting multidimensional array by a second level value

From: Date: Fri, 17 Sep 2004 20:47:38 +0000
Subject: Re: sorting multidimensional array by a second level value
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-197038@lists.php.net to get a copy of this message
the way i did this was by structuting the array like this $array['href'][0] = 'www.com.com'; $array['description'][0] = 'blah!'; etc... then use the array_multisort function like this To sort by "href": array_multisort($array['href'],$array['description'],$array['time']); a key point is that the first element in array_multisort is what the others are sorted by. You can also use flags to get the type of reorder you want. if you're getting the data from a database, try sorting in the query, it'll make your life a lot easier. anyway, hope that helps, -- -------------------------------------------------------------->> Jasper Howard :: Database Administration ApexEleven Web Design 1.530.559.0107 http://www.ApexEleven.com/ <<-------------------------------------------------------------- "Chris Lott" <Chris.Lott@gmail.com> wrote in message news:6b279deb0409171205128e74cd@mail.gmail.com... > I have an array $links like this: > > [1] => Array > ( > [href] => http://www.poetrymagazine.org/epstein_sept_prose.html > [description] => Thank You, No > [time] => 2004-09-17T17:30:32Z > ) > > [2] => Array > ( > [href] => http://110am.com/projects/manuscript/ > [description] => Manuscript > [time] => 2004-09-16T19:25:14Z > ) > > I'd like to sort the array based on one of the values in the field > href, description, or time. Is there a canonical way of doing this? > > c > -- > Chris Lott

« previous php.general (#197038) next »