elias Posted August 19, 2009 Share Posted August 19, 2009 Hi guys and gals! Lets see if I can explain the problem.... I have collated data from various tables to arrive a something like this: CompetitionRankShortLongTotal Barcelona2101525 Madrid1151530 Valencia3121022 I would like to sort this data by "Rank", "Short", "Long" or "Total". To that effect I have managed to introduce the data in to a multidimensional array with the keys values such as: $results[$competition]["elements"] - where $results is the multi-array $competition are teh sub arrays (madrid, barcelona, valencia) "elements" are the values of "rank", "short", "long" and "total" so, echo $results["madrid"]["total"]; // yields 30 //sorry to go on, but I need //to get my head around this still now to the question, how can I sort by "rank", say. have tried array_multisort() but found it only sorts by "row" so to speak. I can sort "Rank", "Short", "Long", "Total" or "2", "10", "15", "25" but not as I want by "column": "25, "30", "22" I have considered dumping everything back into a dummy db table, but thought "there must be a better way". also, thought of "flipping" teh table so teh rows are columns and vice-versa, but cant even begin to think how to do it, apart from creating a function() which would be a last resort. thoughts, leads, suggestions - welcome! thx and keep up the good work! elias Quote Link to comment Share on other sites More sharing options...
msinternet Posted August 19, 2009 Share Posted August 19, 2009 Hi, if it was me I would use numerical indices and maybe a lookup array. Then you can loop through with a for loop to build a second inverted array. Or, in a similar way use a foreach loop to go down a layer and build the second array. Martin Quote Link to comment Share on other sites More sharing options...
elias Posted August 20, 2009 Author Share Posted August 20, 2009 thanks msinternet. but is there no *more elegant* way to do this, or have I explained myself awfully? cheers elias ps. or is it the Bruce Willis avatar putting ppl off :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.