国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

二維數組排序:array_orderby(php官網評論)

2019-11-08 20:05:11
字體:
來源:轉載
供稿:網友
/**I came up with an easy way to sort database-style results. This does what example 3 does, except it takes care of creating those intermediate arrays for you before passing control on to array_multisort(). */<?phpfunction array_orderby(){ $args = func_get_args(); $data = array_shift($args); foreach ($args as $n => $field) { if (is_string($field)) { $tmp = array(); foreach ($data as $key => $row) $tmp[$key] = $row[$field]; $args[$n] = $tmp; } } $args[] = &$data; call_user_func_array('array_multisort', $args); return array_pop($args);}?>The sorted array is now in the return value of the function instead of being passed by reference.<?php$data[] = array('volume' => 67, 'edition' => 2);$data[] = array('volume' => 86, 'edition' => 1);$data[] = array('volume' => 85, 'edition' => 6);$data[] = array('volume' => 98, 'edition' => 2);$data[] = array('volume' => 86, 'edition' => 6);$data[] = array('volume' => 67, 'edition' => 7);// Pass the array, followed by the column names and sort flags$sorted = array_orderby($data, 'volume', SORT_DESC, 'edition', SORT_ASC);?>

轉自:http://php.net/manual/zh/function.array-multisort.php 第一條評論就是。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 勐海县| 安岳县| 修武县| 巴马| 哈尔滨市| 黄浦区| 眉山市| 大英县| 武川县| 滦南县| 原平市| 京山县| 崇阳县| 讷河市| 肇州县| 沁水县| 化州市| 桐城市| 澄迈县| 灵武市| 兴山县| 新化县| 英吉沙县| 蕲春县| 永顺县| 施甸县| 阜新市| 临江市| 广宗县| 沙田区| 乐至县| 讷河市| 定边县| 奉节县| 新田县| 乡宁县| 富川| 姚安县| 荣昌县| 宿州市| 任丘市|