Home > php教程 > php手册 > php按照指定键值对二维数组排序

php按照指定键值对二维数组排序

WBOY
Release: 2016-06-07 11:45:51
Original
1187 people have browsed it

/* 二维数组按指定的键值排序
* $array 数组
* $key排序键值
* $type排序方式
*/function array_sort($arr, $keys, $type = 'desc') {<br>     $keysvalue = $new_array = array();<br>     foreach ($arr as $k => $v) {<br>         $keysvalue[$k] = $v[$keys];<br>     }<br>     if ($type == 'asc') {<br>         asort($keysvalue);<br>     } else {<br>         arsort($keysvalue);<br>     }<br>     reset($keysvalue);<br>     foreach ($keysvalue as $k => $v) {<br>         $new_array[$k] = $arr[$k];<br>     }<br>     return $new_array;<br> }

AD:真正免费,域名+虚机+企业邮箱=0元

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