Sorting a multi-dimensional array in it's entirety

I have a multi dimensional array with various fields of data in it. I need to sort the array by a specific field on the second level of the array and keep all other fields relational. Here's an example of the code:

<PRE>
while ($postdata = mysql_fetch_array($firstresult)) {

    $postarray['structure']['count'] = $postarray['structure']['count'] + 1;
    $postarray['structure']['overview'] .= "\n" . $postdata['pin'];
    $postarray['structure'][$i] = $postdata['pin'];
    $i++;

    $postarray[$postdata[pin]]['username'] = $postdata['username'];
    $postarray[$postdata[pin]]['email'] = $postdata['email'];
    $postarray[$postdata[pin]]['secondemail'] = $postdata['secondemail'];
    $postarray[$postdata[pin]]['emaildisp'] = $postdata['emaildisp'];
    $postarray[$postdata[pin]]['date'] = $postdata['date'];
    $postarray[$postdata[pin]]['subject'] = $postdata['subject'];
    $postarray[$postdata[pin]]['body'] = $postdata['body'];
}
</PRE>

I hope that displays correctly. Here's an example of how it's shown in the browser:

<PRE>
for ($i = 1; $i <= $totalposts; $i++) {

    $currentpin = $postarray[structure][$i];

    echo $postarray[$currentpin]['subject'];
    echo $postarray[$currentpin]['username'];
    echo $postarray[$currentpin]['date'];
}
</PRE>

I hope that gives an idea of what I'm doing. What I want to do is have a function to sort it by a particular field, such as subject, or username, etc.

However for the life of me I can't figure out how to do this with this particular array.

phpaddictAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SynstheCommented:
Well instead of sorting the array itself, why not create an additional array to use as a reference point, and work on that?

Figure out what values you need from the original array, then go through and grab their index/id/whatever. Pipe each one into another array, and then sort that array. Then looping through that array use it's values to get what you need from the original array.


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
phpaddictAuthor Commented:
Thanks, I didn't think of that. I was trying to work entirely on the array itself without using any outside variables, which limited me I guess.

Much easier than writing a user defined function for usort!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.