PHP二维数组排序(list_order)
2023-09-14 08:57:27 时间
/** * 对二维数组进行排序 * 模拟 数据表记录按字段排序 * * <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同时上传“多个”文件示例,并格式化$_FILES数组信息
- PHP如何自动识别第三方Restful API的内容,自动渲染成 json、xml、html、serialize、csv、php等数据
- PHP安装模式cgi、fastcgi、php_mod比较
- PHP中有关正则表达式的函数集锦
- PHP 并发场景的 3 种解决方案
- php:如何使用PHP排序, key为字母+数字的数组(多维数组)
- php与mysql通讯那点事
- 解决ZendStudio打开utf-8格式的php文件乱码
- PHP中extract() array_map call_user_func compact
- PHP读取配置文件类(php,ini,yaml,xml)
- [php-src] Php内核的有趣高频宏
- [php-src] 窥探Php内核中的数组与面向对象
- php 总结
- docker 安装php