Jump to content

[SOLVED] Multi-Dimensional Array Sorts -- can you sort the 4th dimenion by field in 6th?


thepip3r

Recommended Posts

so if this is part of my multi-array:

[submitters] => Array
                        (
                            [14] => Array
                                (
                                    [first_name] => Don
                                    [last_name] => Cheadle
                                    [company] => Hotel Rwanda
                                    [timestamp] => 1238803296
                                    [satisfaction_level] => 0%
                                )

                            [13] => Array
                                (
                                    [first_name] => Jack
                                    [last_name] => Black
                                    [company] => Horribad Inc.
                                    [timestamp] => 1238803244
                                    [satisfaction_level] => 12.5%
                                )

                            [12] => Array
                                (
                                    [first_name] => Mark
                                    [last_name] => Wahlberg
                                    [company] => Shooters R Us
                                    [timestamp] => 1238803181
                                    [satisfaction_level] => 50%
                                )

                            [11] => Array
                                (
                                    [first_name] => Keanu
                                    [last_name] => Reeves
                                    [company] => Matrix Unlimited
                                    [timestamp] => 1238802082
                                    [satisfaction_level] => 62.5%
                                )

                            [10] => Array
                                (
                                    [first_name] => Rhona
                                    [last_name] => Mitra
                                    [company] => Hawtness
                                    [timestamp] => 1238802020
                                    [satisfaction_level] => 100%
                                )

                            [9] => Array
                                (
                                    [first_name] => Cameron
                                    [last_name] => Wilson
                                    [company] => NewGeo
                                    [timestamp] => 1238801573
                                    [satisfaction_level] => 25%
                                )

                            [8] => Array
                                (
                                    [first_name] => John
                                    [last_name] => Candy
                                    [company] => Big Guys R Us
                                    [timestamp] => 1238777161
                                    [satisfaction_level] => 81.25%
                                )

                            [7] => Array
                                (
                                    [first_name] => Christina
                                    [last_name] => Aguillera
                                    [company] => Hawtness
                                    [timestamp] => 1238777105
                                    [satisfaction_level] => 100%
                                )

                            [6] => Array
                                (
                                    [first_name] => Jessica
                                    [last_name] => Beall
                                    [company] => Hawtness Inc.
                                    [timestamp] => 1238777064
                                    [satisfaction_level] => 100%
                                )

                            [5] => Array
                                (
                                    [first_name] => BillyBob
                                    [last_name] => Thornton
                                    [company] => Crazy Co.
                                    [timestamp] => 1238777034
                                    [satisfaction_level] => 50%
                                )

                            [4] => Array
                                (
                                    [first_name] => Morgan
                                    [last_name] => Freeman
                                    [company] => Seven Co.
                                    [timestamp] => 1238776980
                                    [satisfaction_level] => 100%
                                )

                            [3] => Array
                                (
                                    [first_name] => Emin
                                    [last_name] => Em
                                    [company] => 8 Miles of Horribad
                                    [timestamp] => 1238776932
                                    [satisfaction_level] => 0%
                                )

                            [2] => Array
                                (
                                    [first_name] => Gwen
                                    [last_name] => Stephanie
                                    [company] => Lots of Doubt
                                    [timestamp] => 1238776901
                                    [satisfaction_level] => 50%
                                )

                            [1] => Array
                                (
                                    [first_name] => Tom
                                    [last_name] => Sellek
                                    [company] => Three Men Inc.
                                    [timestamp] => 1238776878
                                    [satisfaction_level] => 100%
                                )

                        )

 

can i sort the "submitters" dimension by, say the last_name of the numbered dimension?  i've played around with array_multisort() but am having problems with the results.

Link to comment
Share on other sites

kk so i'm going to figure this out on my own but need some guidance.

 

i'm going to pull out the elements of the array that i want to sort on and put them into a temp array, i'll apply some kind of array sort on that temp array and then reorder the parent array based off of my temp array's sort.  my question is, if the array looks like the sample above:

 

1.  ...can i reorder that array somehow? (i've looked through the array functions and can't see any that fill my needs)

or

2.  if i write the new output to like 'submittersTemp', if i wipe the 'submitters' current key, can I then rename submittersTemp back to submitters?  (i couldn't find any array_key_rename() function). 

Link to comment
Share on other sites

right and i understand this allows me to apply a user defined function to an array but that doesn't answer my question.  my question is about manipulating my array order once it's been sorted.  specifically, how do i go about manipulating the array.  can you reorder the array by an element in a sub array OR is there a way that i can simply rename an array's key.

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.