[nycphp-talk] Sorting 2-dimensional arrays at 2:00 am - UGH!
Hans Zaunere
hans at nyphp.org
Mon Aug 11 12:42:14 EDT 2003
Phil Powell wrote:
> $fbArray[$j] = array($feedbackCategoryArray[$i]['attributes']['NAME'] =>
> $feedbackCategoryArray[$i]['attributes']['DISPLAYNAME']);
>
> I can't begin to fathom in my befuddled mind how to sort this array
> $fbArray into alphabetical order according to
> $feedbackCategoryArray[$i]['attributes']['NAME']
I'll throw this function out there as an example:
function __sortOn( $metadata,$sort_flags,$reverse = FALSE ) {
if( !isset($this->Listing[0][$metadata]) )
return FALSE;
$metakeys = array();
foreach( $this->Listing as $key => $sorton )
$metakeys[$key] = $sorton[$metadata];
if( $reverse )
arsort($metakeys,$sort_flags);
else
asort($metakeys,$sort_flags);
$tmp = array();
foreach( $metakeys as $key => $metakey )
$tmp[] = $this->Listing[$key];
$this->Listing = $tmp;
return TRUE;
}
> - I am utterly lost,
> can someone explain in detail how I would do it and why.
I have no idea why, but I'd consider rethinking your data structures a bit :)
H
More information about the talk
mailing list