PHP二维数组排序(list_order)
2016-07-14 01:16
711 查看
/** * 对二维数组进行排序 * 模拟 数据表记录按字段排序 * * <code> * @list_order($list, $get['orderKey'], $get['orderType']); * </code> * @param array $array 要排序的数组 * @param string $orderKey 排序关键字/字段 * @param string $orderType 排序方式,'asc':升序,'desc':降序 * @param string $orderValueType 排序字段值类型,'number':数字,'string':字符串 * @link http://www.cnblogs.com/52php/p/5668809.html */ function list_order(&$array, $orderKey, $orderType = 'asc', $orderValueType = 'string') { if (is_array($array)) { $orderArr = array(); foreach ($array as $val) { $orderArr[] = $val[$orderKey]; } $orderType = ($orderType == 'asc') ? SORT_ASC : SORT_DESC; $orderValueType = ($orderValueType == 'string') ? SORT_STRING : SORT_NUMERIC; array_multisort($orderArr, $orderType, $orderValueType, $array); } }
应用:
@list_order($list, $get['orderKey'], $get['orderType'], "string");
延伸阅读:
PHP array_multisort() 函数详解 及 二维数组排序(模拟数据表记录按字段排序)
相关文章推荐
- php数组函数中的array_slice和array_flip
- PHP之session机制和优化
- PHP正则表达式抓取某个标签的特定属性值的方法
- PHP继承竟然也需要显性基因?
- PHP 调试 问号,乱码 ,编码
- PHP爬虫:百万级别知乎用户数据爬取与分析
- php 日期时间增加一个月一天,把日期转为时间戳
- FTP命令
- php 在页面中调试错误(解决php错误500)
- PHP Error Handling API方法归纳总结.md
- coreseek+php之sphinx扩展安装+php调用示例
- ThinkPHP基础(一)搭建环境
- PhpStorm 设置自动FTP同步文件
- [php学习四]AJAX练习1
- PHP第七课 类和对象
- 使用phpize建立php扩展 Cannot find config.m4.
- phpmailer发送邮件 SMTP Error: Could not authenticate 错误
- FTP 文件传输协议(转)
- 使用phpmaill发送邮件的例子
- PHP笔记