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.
高洛峰2017-05-16 13:16:01
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;
}