Home > php教程 > php手册 > body text

分享个PHP二维数组按照指定的字段排序的函数

WBOY
Release: 2016-06-07 11:34:14
Original
1316 people have browsed it

分享个PHP二维数组按照指定的字段排序的函数
最近一直都在开发二代旅游网站程序和二代旅游CMS,官方网站http://www.erdaicms.com,有兴趣的朋友可以看看,

下面言归正传,开发的时候要用到数组排序,所以就研究了下,分享出来,,PHP一维数据排序,我们都知道,用自带的各种函数就可以了,二维数据排序,就的自己写了,代码如下/**<br>  * 二维数组根据字段进行排序<br>  * @params array $array 需要排序的数组<br>  * @params string $field 排序的字段<br>  * @params string $sort 排序顺序标志 SORT_DESC 降序;SORT_ASC 升序<br>  */<br>  function arraySequence($array, $field, $sort = 'SORT_DESC')<br> {<br>     $arrSort = array();<br>     foreach ($array as $uniqid => $row) {<br>         foreach ($row as $key => $value) {<br>             $arrSort[$key][$uniqid] = $value;<br>         }<br>     }<br>     array_multisort($arrSort[$field], constant($sort), $array);<br>     return $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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!