php - Sort associative array
天蓬老师
天蓬老师 2017-05-16 13:14:01
0
2
628

Array
id Name Age Language
1 Novel 16 90
2 Xiaomeng 18 93
2 Kitten 17 92
Question:
This is a table.
1: How to sort by age from smallest to largest?
2: How to sort by Chinese language from smallest to largest?
3: ID sorting is the default, so don’t use it╮( ̄▽ ̄"")╭
Simply put, the associative array is sorted by a certain key.

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
我想大声告诉你

arr.sort((a, b)=> { return a.age - b.age })

Other similar

小葫芦

Learn about this function: array_multisort()

function arr_sort($arr,$key_name){
        $sort = array();
        foreach ($arr as $key => $value)
        {
            $sort[$key] = $value["$key_name"];
        }
        array_multisort($sort, SORT_ASC , $arr);

        return $arr;
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template