[
[0]=>[adminid =>1,group =>小组1],
[1]=>[adminid =>2,group =>小组2],
[2]=>[adminid =>2,group =>小组3]
];
如何让adminid 相同的放进同一个下标?
拼成这样的:
[
[0]=>[adminid =>1,group =>小组1],
[1]=>[
[0]=>[adminid =>2,group =>小组2],
[1]=>[adminid =>2,group =>小组3]
]
];
迷茫2017-02-24 09:27:28
看你的数组吧,如果数组不是很大,循环就可以了。但是数组太大,会消耗内存,需要想一些特别的办法。
public function actionTest(){ $list = []; $arr = [ ['adminid' => 1, 'group' => '小组1'], ['adminid' => 2, 'group' => '小组2'], ['adminid' => 2, 'group' => '小组3'], ]; foreach ($arr as $value) { if (isset($list[$value['adminid']])) { $list[$value['adminid']][] = $value; continue; } $list[$value['adminid']][] = $value; } unset($arr); print_r($list); }