根据字段seller_id合并数组数组$result如下Array(
[0] => Array
(
[seller_id] => 17140
[bp_counts] => 1
)
[1] => Array
(
[seller_id] => 17140
[dr_counts] => 9
)
[3] => Array
(
[seller_id] => 17140
[dc_counts] => 10
)
)希望得到的数组为Array(
[0] => Array
(
[seller_id] => 17140
[bp_counts] => 1
[dr_counts] => 9
[dc_counts] => 10
)
)求大神帮忙解决,谢谢。。。
2 回答
鸿蒙传说
TA贡献1865条经验 获得超7个赞
function field_merge($data){
foreach ($data as $v) { foreach ($v as $m => $n) { if(!isset($result[$m])){ $result[$m] = $n; } } } $return[] = $result;return $return;
}
茅侃侃
TA贡献1842条经验 获得超21个赞
function field_merge($data, $field = 'seller_id') {
$result = [];
foreach ($data as $item) {
if (!isset($result[$item[$field]])) {
$result[$item[$field]] = [];
}
$result[$item[$field]] = array_merge($result[$item[$field]] ?: [], $item);
}
return array_values($result);
}
- 2 回答
- 0 关注
- 228 浏览
添加回答
举报
0/150
提交
取消