This article mainly talks about using PHP to sort two-dimensional data. It has certain reference value. Interested friends can learn about it.
Sorting of one-dimensional arrays is relatively simple, such as using sort(), asort(), arsort() and other functions, but it is more troublesome for two-dimensional arrays. Let’s summarize all the information on the Internet
// 对二维数组进行指定key排序 $arr 二维数组 ,$shortKey 需要排序的列,$short 排序方式 $shortType 排序类型 function multi_array_sort($arr,$shortKey,$short=SORT_DESC,$shortType=SORT_REGULAR) { foreach ($arr as $key => $data){ $name[$key] = $data[$shortKey]; } array_multisort($name,$shortType,$short,$arr); return $arr; }
Related tutorials: PHP video tutorial
The above is the detailed content of How to sort 2D data using php. For more information, please follow other related articles on the PHP Chinese website!