Jump to content

Manually Sorting Associative Arrays


ShadowMage

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...