How to sort 2D data using php

little bottle
Release: 2023-04-06 08:52:02
forward
2531 people have browsed it

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;
}
Copy after login

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!

Related labels:
php
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template