Jump to content

Manually Sorting Associative Arrays


Recommended Posts

I have the following array:

$arrTest = array('ssmith' => array(1=>'Smith, Sally', 2=>10, 3=>50000),				 'jdoe' => array(1=>'Doe, John', 2=>15, 3=>100000),				 'jadoe' => array(1=>'Doe, Jane', 2=12, 3=>65000),				 'jbequick' => array(1=>'Bequick, Jack', 2=>18, 3=>115000));

I need to be able to sort the array based on the full name (and, obviously, maintain key associations). I cannot just use ksort because of how they are written. For example, John Doe and Jane Doe would normally have the same id (first initial followed by last name) 'jdoe'. But since the same id cannot exist, Jane's first two letters are used. This creates a problem when sorting with Jack Bequick (jbequick) because jadoe is alphabetically "higher" than jbequick. In reality, Jack Bequick should come first. I have tried to wrap my mind around how I would accomplish this, but I just can't seem to formulate a decent loop that would make this work. Any advice?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...