Sorting multidimensional array, upper case being sorted before lowercase

后端 未结 2 840
名媛妹妹
名媛妹妹 2021-01-25 02:51

Using the below for sorting a multidimensional array by screen name:

$sortArray = array();

foreach($members as $member){
    foreach($member as $key=>$value)         


        
2条回答
  •  感情败类
    2021-01-25 03:34

    uasort() should work for you

    'Greg'),
        array('screen_name'=>'Allen'),
        array('screen_name'=>'dan'),
        array('screen_name'=>'Brenda'),
    );
    
    // uasort() like a boss!
    uasort($members, 'sort_by_screen_name');
    
    print_r($members);
    

    Output

    Array
    (
        [1] => Array
            (
                [screen_name] => Allen
            )
    
        [3] => Array
            (
                [screen_name] => Brenda
            )
    
        [2] => Array
            (
                [screen_name] => dan
            )
    
        [0] => Array
            (
                [screen_name] => Greg
            )
    
    )
    

    Note: the original array keys are preserved using this method. If you'd like the keys to be rewritten, you can simply use usort().

提交回复
热议问题