Jump to content

flipping and sorting a multi dimensional array


elias

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.