ShadowMage Posted December 15, 2011 Report Share Posted December 15, 2011 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 More sharing options...
dsonesuk Posted December 15, 2011 Report Share Posted December 15, 2011 can't you just sort by fullname and add another array value with a sort number, and then sort by that number. Link to comment Share on other sites More sharing options...
ShadowMage Posted December 15, 2011 Author Report Share Posted December 15, 2011 Not quite sure I understand what you're getting at. Could you maybe show me an example? I did find a solution using uasort, which works great, but I'd like to see your suggestion, too. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now