multi-dimension array value sorting in php

Posted by David on Stack Overflow See other posts from Stack Overflow or by David
Published on 2010-04-23T14:37:41Z Indexed on 2010/04/23 15:13 UTC
Read the original article Hit count: 289

Another potentially interesting (or n00b, whatever comes first) question.

I am building up an array with a set of database fields with information about table, actual field name and descriptive field name as a multi-dimensional array. Here is what it currently looks like:

$Fields['User']['ID'] = "User ID";
$Fields['User']['FirstName'] = "First Name";
$Fields['Stats']['FavouriteOrder'] = "Favourite Item Ordered";
$Fields['Geographic']['Location'] = "Current Location";
$Fields['Geographic']['LocationCode'] = "Current Location Code";

Okay, this is fine, but I am piping this into a system that allows exporting of selected fields, and in the end I want to foreach() through the different levels, extract the data and then ultimately have all the descriptive fields to be displayed sorted alphabetically using their descriptive name. So ultimately in the order: Current Location, Current Location Code, Favourite Item Ordered, First Name then User ID - obviously keeping index associations.

I can't use usort() and I can't use array_multisort()... or maybe I can and I just don't know how. usort() seems to need a key to sort by, but I have variable keys. array_multisort() just seems to do the same as sort() really.

Any ideas?

© Stack Overflow or respective owner

Related posts about php

Related posts about sorting