Sorting multidimensional Arrays maintaining index associations

Discussion in 'PHP' started by Kendothpro, Jul 19, 2007.

  1. #1
    I need to order an array like it was a SQL result set, so let's say I have:

    $result['domains'][0]='e.com';
    $result['domains'][1]='a.com';
    $result['domains'][2]='d.com';

    $result['active'][0]=true;
    $result['active'][1]=false;
    $result['active'][2]=true;

    How do I order the array alphabetically by the 'domains' index, while keeping associations with the 'active' index? something like 'ORDER BY 'domains' ASC' in SQL? I've tried array_multisort but it doesn't seem to keep associations and frankly I never understood how it works, it just confuses me :/
     
    Kendothpro, Jul 19, 2007 IP
  2. ecentricNick

    ecentricNick Peon

    Messages:
    351
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There is no "association" between domains and active. That's just a concept you have in your mind. (Didn't mean that to sound rude - sorry!) They just happen to be in the same order.

    If you want an association, you should create an element that physically associates them.

    But, I think if you're trying to do "databse type stuff" you should use a database!
     
    ecentricNick, Jul 19, 2007 IP