Link to home
Start Free TrialLog in
Avatar of shaungallagher
shaungallagher

asked on

Sort multi-dim array

I have a multi-dimensional array of the following type:

$main['fname'][1] = "Bob"
$main['lname'][1] = "Dole"
$main['fname'][2] = "Bill"
$main['lname'][2] = "Clinton"
$main['fname'][3] = "George"
$main['lname'][3] = "Bush"

I'd like to sort the array values alphabetically by last name ('lname') such that the return values will be:

$main['fname'][1] = "George"
$main['lname'][1] = "Bush"
$main['fname'][2] = "Bill"
$main['lname'][2] = "Clinton"
$main['fname'][3] = "Bob"
$main['lname'][3] = "Dole"

Can anyone suggest a way to do this?

Avatar of Thunder27
Thunder27

hi...  PHP's array_multisort should help

ex:

array_multisort ($main["lname"], SORT_STRING, SORT_DESC, $main["fname"]);


Note: If you have more columns, list them at the end.
Avatar of shaungallagher

ASKER

Yikes!  I forgot to mention that I'm only able to use PHP3, not PHP4, so array_multisort won't work for me.  Is there any PHP3 equivalent?
Oh, bummer... I can't think of any right off, but I'll ask around
ASKER CERTIFIED SOLUTION
Avatar of waygood
waygood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial