1
onlyhot 2017-02-12 10:31:21 +08:00 via iPhone
转换成数组处理
|
2
imlonghao673 2017-02-12 10:36:14 +08:00 via Android
最后面的
}, 前面有? |
4
byxiaozhe OP @imlonghao673 fupdz 前面那个{就是 只是后面忘记加了个]
|
5
mhycy 2017-02-12 10:43:10 +08:00
唯一方式:遍历重构
|
6
qiayue 2017-02-12 10:44:39 +08:00
循环,然后判断 fupdz 一致则放一起
|
8
mhycy 2017-02-12 10:52:06 +08:00
function convertFupdzData($source) {
$fupdz_arr = []; foreach($source as $item) { if(array_key_exists($item['fupdz'], $fupdz_arr)) { $fupdz_arr[$item['fupdz']][] = $item; } else { $fupdz_arr[$item['fupdz']] = [$item]; } } $result = []; foreach($fupdz_arr as $fupdz => $data) { $result[] = [ "fupdz" => strval($fupdz), "data" => $data ]; } return $result; } |
10
byxiaozhe OP @mhycy
$query = DB::query("SELECT * FROM " . DB::table('forum_forum') . " WHERE type='group' and status=1 ORDER BY fid ASC"); $ar=array(); while ($soft = DB::fetch($query)) { $querys = DB::query("SELECT * FROM " . DB::table('forum_forum') . " WHERE fup=".$soft['fid']." and status=1 ORDER BY fid ASC"); while ($softs = DB::fetch($querys)) { $queryss = DB::query("SELECT * FROM " . DB::table('forum_forumfield') . " WHERE fid=".$softs['fid']." ORDER BY fid ASC"); while ($softss = DB::fetch($queryss)) { $ar[] = array("fupdz"=>$soft['fid'],"data"=>array(array("id"=>$softs['fid'],"fup"=>$softs['fup'],"name"=>iconv('gb2312','utf-8',$softs['name']),"px"=>$softs['displayorder'],"icon"=>$softss['icon']))); } } } 如何添加你刚发的那个 这是源代码 |
11
m939594960 2017-02-12 11:40:22 +08:00
@byxiaozhe #10 我只能说你这个代码写的真是 666 啊
|
13
fytriht 2017-02-12 14:02:50 +08:00
```javascript
const sort = (arr) => { let hash = {} let newArr = [] let i = 0 for (let item of foo) { if (hash[item.fupdz] == undefined) { hash[item.fupdz] = i newArr.push(item) i++ } else { const idx = hash[item.fupdz] const data = item.data data.forEach(item => newArr[idx].data.push(item)) } } return newArr } ``` 这样写应该没问题,楼主试试 |
14
fytriht 2017-02-12 14:04:25 +08:00
v2 的回复功能太坑,不支持 markdown 还把代码缩进给吃了....
|