Sorting an array in PHP based on different values

Posted by Jimbo on Stack Overflow See other posts from Stack Overflow or by Jimbo
Published on 2010-06-12T00:07:32Z Indexed on 2010/06/12 0:12 UTC
Read the original article Hit count: 473

Filed under:
|

I have an array whose elements are name, reversed_name, first_initial and second_initial. A typical row is "Aaron Smith", "Smith, Aaron", "a", "s". Each row in the array has a first_initial or second_initial value of "a".

I need to display the rows alphabetically but based on the "a" part, so that either the name or reversed_name will be displayed. An example output would be:

  • Aaron Smith
  • Abbot, Paul
  • Adrian Jones
  • Anita Thompson
  • Atherton, Susan

I really have no idea how to sort the array this way so any help will be much appreciated!

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays