#1
  1. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,616
    Rep Power
    595

    SORT_FLAG_CASE flag not working


    I am trying to do a case insensitive sort on a 2 dimensional array.
    PHP Code:
    foreach ($rows as $key=>$row) {
        
    $names[$key]=$row['Name'];
    }
    array_multisort($rows,SORT_STRING|SORT_FLAG_CASE,$names); 
    This yields the same result (lower case after all upper case) with or without the case flag. Perhaps new eyes can see what I am missing. TIA.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    What version of PHP are you using? SORT_FLAG_CASE only exists in 5.4+.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,616
    Rep Power
    595
    Ah! 5.3.3. Is there an alternative to upgrading?

    I'm betting you are going to say 'uksort'.
    Last edited by gw1500se; January 19th, 2013 at 03:15 PM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  6. #4
  7. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,316
    Rep Power
    7171
    Just make all of the values you put into $names lowercase or uppercase.

    Also you have the order of the $names and $rows arguments reversed in the call to array_multisort.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    If you can't change the data on the way into the array (like if it comes from a database call) then you can use [PHPNET="array_walk"]array_walk[/PHPNET]
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo