Home > php教程 > PHP源码 > body text

Two-dimensional array sorted by a certain column

WBOY
Release: 2016-07-06 13:28:27
Original
1190 people have browsed it
Jump to [1] [Full screen preview]
/**
 * 二维数组排序方法,数字的倒叙排列
 * @param arr
 * @param field
 */
function sortArrByField(&$array, $field, $desc = false){
    $fieldArr = array();
    foreach ($array as $k => $v) {
        $fieldArr[$k] = $v[$field];
    }
    $sort = $desc == false ? SORT_ASC : SORT_DESC;
    array_multisort($fieldArr, $sort, $array);
 
    return $array;
}
Copy after login
source:php.cn
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template