PHP二维数组排序

来源:互联网 发布:centos 光盘 yum源 编辑:程序博客网 时间:2024/05/16 15:30
/** * 对二维数组进行排序 * 模拟 数据表记录按字段排序 * * <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.php-note.com/article/detail/6eab2985dd5a49a98e6b4ee81bc5922f */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);}}


0 0
原创粉丝点击